31 Input/output library [input.output]

31.10 File-based streams [file.streams]

31.10.3 Class template basic_filebuf [filebuf]

31.10.3.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 141.
If mode is not some combination of flags shown in the table then the open fails.
Table 141: File open modes [tab:filebuf.open.modes]
ios_base flag combination
stdio equivalent
binary
in
out
trunc
app
noreplace
+
"w"
+
+
"wx"
+
+
"w"
+
+
+
"wx"
+
+
"a"
+
"a"
+
"r"
+
+
"r+"
+
+
+
"w+"
+
+
+
+
"w+x"
+
+
+
"a+"
+
+
"a+"
+
+
"wb"
+
+
+
"wbx"
+
+
+
"wb"
+
+
+
+
"wbx"
+
+
+
"ab"
+
+
"ab"
+
+
"rb"
+
+
+
"r+b"
+
+
+
+
"w+b"
+
+
+
+
+
"w+bx"
+
+
+
+
"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).298
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.
native_handle_type native_handle() const noexcept;
Preconditions: is_open() is true.
Returns: The native handle associated with *this.
298)298)
The macro SEEK_END is defined, and the function signatures fopen(const char*, const char*) and fseek(FILE*, long, int) are declared, in <cstdio>.