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] . 回答1: 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). 回答2: The strerror function from <cstring> might be useful. This isn't necessarily standard or portable, but