29 Input/output library [input.output]

29.9 File-based streams [file.streams]

29.9.2 Class template basic_­filebuf [filebuf]

29.9.2.4 Member functions [filebuf.members]

bool is_open() const;
Returns: true if a previous call to open succeeded (returned a non-null value) and there has been no intervening call to close.
basic_filebuf* open(const char* s, ios_base::openmode mode); basic_filebuf* open(const filesystem::path::value_type* s, ios_base::openmode mode); // wide systems only; see [fstream.syn]
Preconditions: s points to a NTCTS ([defns.ntcts]).
Effects: If is_­open() != false, returns a null pointer.
Otherwise, initializes the filebuf as required.
It then opens the file to which s resolves, if possible, as if by a call to fopen with the second argument determined from mode & ~ios_­base​::​ate as indicated in Table 126.
If mode is not some combination of flags shown in the table then the open fails.
Table 126: File open modes [tab:filebuf.open.modes]
ios_­base flag combination
stdio equivalent
binary
in
out
trunc
app
+
"w"
+
+
"w"
+
+
"a"
+
"a"
+
"r"
+
+
"r+"
+
+
+
"w+"
+
+
+
"a+"
+
+
"a+"
+
+
"wb"
+
+
+
"wb"
+
+
+
"ab"
+
+
"ab"
+
+
"rb"
+
+
+
"r+b"
+
+
+
+
"w+b"
+
+
+
+
"a+b"
+
+
+
"a+b"
If the open operation succeeds and ios_­base​::​ate is set in mode, positions the file to the end (as if by calling fseek(file, 0, SEEK_­END), where file is the pointer returned by calling fopen).326
If the repositioning operation fails, calls close() and returns a null pointer to indicate failure.
Returns: this if successful, a null pointer otherwise.
basic_filebuf* open(const string& s, ios_base::openmode mode); basic_filebuf* open(const filesystem::path& s, ios_base::openmode mode);
Returns: open(s.c_­str(), mode);
basic_filebuf* close();
Effects: If is_­open() == false, returns a null pointer.
If a put area exists, calls overflow(traits​::​​eof()) to flush characters.
If the last virtual member function called on *this (between underflow, overflow, seekoff, and seekpos) was overflow then calls a_­codecvt.unshift (possibly several times) to determine a termination sequence, inserts those characters and calls overflow(traits​::​​eof()) again.
Finally, regardless of whether any of the preceding calls fails or throws an exception, the function closes the file (as if by calling fclose(file)).
If any of the calls made by the function, including fclose, fails, close fails by returning a null pointer.
If one of these calls throws an exception, the exception is caught and rethrown after closing the file.
Postconditions: is_­open() == false.
Returns: this on success, a null pointer otherwise.
The macro SEEK_­END is defined, and the function signatures fopen(const char*, const char*) and fseek(FILE*, long, int) are declared, in <cstdio>.
 â®¥