Rothbard
asked on
Using cout for string
I have a question about the following simple c++ program
#include <iostream>
using namespace std;
int main()
{
while (cin >> s)
{
cout << s << endl;
}
return 0;
}
This program just reads text into a string from the standard input, then outputs it to the screen via std::cout. My question if one enters lots of separate words separated by spaces and terminated by EOF, the program will output each word on a separate line. Why does this happen?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you want to read one line you have to use
std::getline(std::cin, s);