On Tue, 05 Feb 2013 15:11:28 +0100, Steve Keller wrote:
> How can I get the reason for a file operation failure, say after
> fstream:
pen() or fstream::read()?
>
> In C, after fopen(), fread(), etc. you can check errno or get a message
> using perror() and strerror().
Nothing in the C standards require fopen() or fread() to set errno on
failure. More generally, the standards only define the values EDOM, EILSEQ
and ERANGE, so anything else is implementation-dependent.
> I cannot find any equivalent for C++ fstreams.
fstream:

pen() calls fstream::rdbuf()->open(), which operates "as if by
calling std::fopen()" (27.9.1.4[filebuf.members]p2).
In C++11, <cerrno> is aligned with POSIX rather than C, so EEXIST etc are
defined. However, fopen() is defined by reference to the C standard,
which doesn't specify its behaviour on failure with respect to errno (see
above). And POSIX doesn't mention C++.
So I guess it all depends upon what you want to read into "as if by
std::fopen()".