CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Opening Files

  1. #1
    Join Date
    Jan 2002
    Posts
    19

    Opening Files

    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

  2. #2
    Join Date
    Jan 2002
    Posts
    19
    Bueller...

  3. #3
    Join Date
    Dec 2002
    Posts
    287
    You can always use GetLastError() (or something similar to figure out the last error).
    Anyway, ofstream:pen 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured