# c++ istream opens non-existant file

## Recommended Posts

supagu    148
i had a problem yesterday where i have an istream (ifstream) and i open a file, i got the spelling wrong, and i did a call to is_open which returned true, is there a proper way to check if a file is open or if the stream has just made an empty "file"?

##### Share on other sites
I believe calling open() is your trouble. Once you call that it creates the file, if it wasn't there already.

The MSDN docs on ifstream suggest the following:
istream ifile( "FILENAME" );if ( ifile.fail() )// The file does not exist ...