Answer the question
In order to leave comments, you need to log in
Cin how to detect the end of a stream?
There is such a program:
string n;
while (cin >> n) {
cout << n;
}
Answer the question
In order to leave comments, you need to log in
if there are only whitespace characters in the stream, cin >> n will simply ignore them, and if it reaches the end of the stream, then cin >> n will be interpreted as false, in fact, the exit will happen anyway. I don't think you've covered the whole issue...
You can catch the end of a line:
string n;
do
{
cin >> n;
cout << n;
}while(cin.peek() != '\n'))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question