The code cin >> y;
only reads in one word, not the whole line. To get a line, use:
string response;
getline(cin, response);
Then response
will contain the contents of the entire line.
More Related Contents:
- Why is iostream::eof inside a loop condition (i.e. `while (!stream.eof())`) considered wrong?
- Why does std::getline() skip input after a formatted extraction?
- “std::endl” vs “\n”
- Why would we call cin.clear() and cin.ignore() after reading input?
- How to print (using cout) a number in binary form?
- C++ Standard Library: How to write wrappers for cout, cerr, cin and endl?
- Does the C++ standard mandate poor performance for iostreams, or am I just dealing with a poor implementation?
- How to properly overload the
- ‘printf’ vs. ‘cout’ in C++
- Restore the state of std::cout after manipulating it
- Which C I/O library should be used in C++ code? [closed]
- How to get IOStream to perform better?
- How do I deal with the max macro in windows.h colliding with max in std?
- How to solve “Unresolved inclusion: ” in a C++ file in Eclipse CDT?
- How to write custom input stream in C++
- Standard no-op output stream
- How can I compose output streams, so output goes multiple places at once?
- Find all substring’s occurrences and locations
- How to print __int128 in g++?
- Custom manipulator for C++ iostream
- How do the stream manipulators work?
- Obtain a std::ostream either from std::cout or std::ofstream(file)
- How to easily make std::cout thread-safe?
- How to disable buffering on a stream?
- How to make cout behave as in binary mode?
- Why can’t std::ostream be moved?
- Loading a file into a vector
- generic way to print out variable name in c++
- How to detect negative numbers as parsing errors when reading unsigned integers?
- Are there binary memory streams in C++