Sign in to follow this  
supagu

c++ istream opens non-existant file

Recommended Posts

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 this post


Link to post
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 ...



Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this