Search code examples
c++iostream

Detecting reason for failure to open an ofstream when fail() is true


Seems like this should be simple, but I don't find it in a net search.

I have an ofstream which is open(), and fail() is now true. I'd like to know the reason for the failure to open, like with errno I would do sys_errlist[errno].


Solution

  • Unfortunately, there is no standard way of finding out exactly why open() failed. Note that sys_errlist is not standard C++ (or Standard C, I believe).