Click to See Complete Forum and Search --> : Opening Files


defunct
December 13th, 2002, 12:02 PM
Hello,

Is there a way to see why a file didn't open using the ofstream class? In C, you can check the errno and it will tell you why it didn't open (i.e. wrong permissions, file didn't exist, etc...). Is this possible with ofstream?

Thanks,
-d

defunct
December 14th, 2002, 12:24 AM
Bueller...

DanM
December 14th, 2002, 04:11 AM
You can always use GetLastError() (or something similar to figure out the last error).
Anyway, ofstream::open documentation says:

"Opens a disk file and attaches it to the stream’s filebuf object. If the filebuf object is already attached to an open file, or if a filebuf call fails, the ios::failbit is set. If the file is not found, the ios::failbit is set only if the ios::nocreate mode was used."

Other way is to call ofstream::is_open:

"Returns a nonzero value if this stream is attached to an open disk file identified by a file descriptor; otherwise 0."

Dan