when i enter a file that exists, myfile.good() returns good then if i try a file that does not exist the like myfile.good() returns true again. If i start the program and i try first a file that does not exist then myfile.good() returns false.

I do not know why after i enter a valid file myfile.good() will continue to return true.

This is mainly what my question is about and the problem i cant figure out.
– user1082764Jun 12 '13 at 0:23

1

Chances are, if you started with a valid file then changed to an invalid file, the stream is still ready for I/O. Which I would consider a bug, but hey, C++.
– 2rs2tsJun 12 '13 at 0:34

1

Yep, it's exactly that. good() only returns false when any of the following return true: bad(), fail(), and eof(). fail() is a superset of bad(), and returns true if a r/w operation fails or a format error happens - which will happen with an invalid file, but apparently the flag does not get re-set. Use clear() to reset the flags.
– 2rs2tsJun 12 '13 at 0:38