I'm new to C++. I'm sorry if this question is duplicated but I just can't find similar question.
very basic code:
string s;
while (cin >> s)
cout << s << endl;
I expect the loop stop when I press the return in my keyboard. But it never stop....
I know that cin will return false when it encounters invalid input, for example if we use
int i;
while (cin >> i)
cout << i << endl;
then the loop ends when we enter a non-integer.
But in case of string, how can we stop that loop?