EDIT: please note, in the example below, I show you "how to detect EOF". As @Billy has pointed out, you probably want to use good()
instead of eof()
to detect any error condition or eof. I had included information about this at the end of my answer, but it's important, so I'm adding this note at the top to ensure that it's clear.
(original answer follows)
You want this:
string input;
while( !cin.eof() ) {
getline(cin, input);
}
using operator!
on an iostream
only checks whether a failure or other error condition has occurred. ios::operator!().
You can use good()
in place of !eof()
to check for any of the conditions eof
, badbit
, or failbit
. ios::good().