|
|
|
c++ ofstream C++ ofstream, errno
|
|
|
Hello, Is it possible to check why a file was unable to open using the ofstream class? In C you can check errno, is there something similar for ofstream? Thank you in advance, -d [ Send an empty e-mail to c++
This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
for info ] [ about comp.lang.c++.moderated. First time posters: do this! ]
|
|
|
|
|
|
|
The administrator has disabled public write access. |
|
|
|
c++ ofstream C++ ofstream, errno
|
|
|
On 14 Dec 2002 06:52:51 -0500,
This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
(defunct) wrote in comp.lang.c++.moderated: Hello, Is it possible to check why a file was unable to open using the ofstream class? In C you can check errno, is there something similar for ofstream? Thank you in advance, -d There is no standard way, in either C or C++. The fact that your implementation sets errno to some value that you consider useful when fopen() fails is in fact a non-portable extension. The C standard does not require that fopen() set errno on failure. I would suggest consulting your compilers documentation to see if it provides a similar extension for C++.
|
|
|
|
|
|
|
The administrator has disabled public write access. |
|
|
|
c++ ofstream C++ ofstream, errno
|
|
|
Hello, Is it possible to check why a file was unable to open using the ofstream class? In C you can check errno, is there something similar for ofstream? You can check the stream's state. If the file could not be open (or read from), one of the flags would be set. You can simply ask: if ( stream.fail()) std::cout << could not open/ read file ; or more specific, ask for the std::ios__base_::failbit flag, like this: if ( stream.rdstate() & std::ios__base_::failbit) std::cout << could not open/ read file ; Hope this helps. Check your documentation: there's a lot more to know about the state of a stream. I would recommend the C++ Language 3rd ed, where there's a whole chapter on streams. Best, John
|
|
|
|
|
|
|
The administrator has disabled public write access. |
|