Quote Originally Posted by Micko
I totally agree, when you encounter EOF or other error, test condition in while loop will become false and loop exits.
However you can check especially for EOf with something like this:
Code:
if (ifstream::eofbit)
	cout<<"EOF";
of course after exiting the loop.
I'm not sure if this is correct way to know for sure if loop exit because of EOF. Can you agree with this?
Sure, you could use state flags to test for eof. I believe it is ios_base::eofbit. You can read the flags directly and do bitwise comparisons, though I prefer to use the built in functions...

good()
eof()
fail()
bad()

...so, in the code above I would add:

Code:
if (in.eof()) cout << ""EOF";
else I would need something like this:

Code:
ifstream::iostate s = in.rdstate();
if (s & ifstream::eofbit)
	cout << "EOF\n\n";
I like the first because it is much more concise.

Have a nice day!
-Rog