ofstream::is_open
bool is_open ( ); | ofstream |
cplusplus.com |
Check if a file has been opened.
Checks if the stream is currently associated with a valid file buffer.
Parameters.
Return Value.
If a file has successfully been opened (i.e. the stream is associated with a valid file
buffer) the member function returns true,
otherwise false is returned.
Example.
// ofstream::is_open
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ofstream outfile;
outfile.open ("test.txt");
if (outfile.is_open())
{
outfile << "Output operation successfully performed\n";
outfile.close();
}
else
{
cout << "Error opening file";
}
return 0;
}
This example uses is_open to check if the file has successfully been opened, if so
writes a sentence to the file, otherwise shows an error message on the standard output.
Basic template member declaration ( basic_ofstream<charT,traits> ):
bool is_open (); |
See also.
open
ofstream class