To determine this, the function calls: rdbuf()->is_open()
The stream is associated with a file if either a previous call to member open succeeded or if the object was successfully constructed using the parameterized constructor, and close has not been called since.
Parameters
noneReturn Value
true if a file is open, i.e. associated to this stream object.false otherwise.
Example
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
This example uses is_open to check whether the file has successfully been opened; If so, it writes a sentence to the file, otherwise it prints out an error message.
Basic template member declaration
( basic_ofstream<charT,traits> ) |
See also
| ofstream::open | Open file (public member function) |
| ofstream::close | Close file (public member function) |
