I assume the end of input is when user presses Ctrl+Z (that imitates
'\n' || EOF
As explained by OP: This is typical Windows behavior, where the Ctrl+Z symbol must be at the beginning of the line or it will not work as expected.
So if you input "foo", then send the
EOF signal by pressing Ctrl+Z and then input "bar", "foo" will be read as expected and then
EOF will wait in the input buffer until "bar" is typed too. The program, as is, will stop at
EOF and "bar" will be ignored, even though the user typed it.
Read more in C++ Issue with cin and CTRL + Z.