ofstream::close | public member function |
void close ( ); |
Close file
Closes the file currently associated with the object, disassociating it from the stream. Any pending output sequence is written to the physical file.
The function effectively calls rdbuf()->close().
The function fails if no file is currently open (associated) with this object.
On failure, the failbit internal state flag is set (which can be checked with member fail), and depending on the value set with exception an exception may be thrown.
Parameters
noneReturn Value
noneExample
// ofstream::open #include <fstream> using namespace std; int main () { ofstream outfile; outfile.open ("test.txt", ofstream::out | ofstream::app); outfile << "This sentence is appended to the file content\n"; outfile.close(); return 0; } |
This example opens a file and appends a sentence to its content.
Basic template member declaration
( basic_ofstream<charT,traits> )
void close ( );
|
See also
ofstream::open | Open file (public member function) |
filebuf::close | Close file (public member function) |