std::basic_fstream::open

void open( const char *filename, ios_base::openmode mode = ios_base::in|ios_base::out ); (1) void open( const std::string &filename, ios_base::openmode mode = ios_base::in|ios_base::out ); (2) (since C++11) Opens and associates the file with name filename with the file stream. Calls setstate(failbit) on failure. Calls clear() on success. (since C++11) 1) Effectively calls rdbuf()->open(filename, mode). (see std::bas

std::basic_fstream::rdbuf

std::basic_filebuf<CharT, Traits>* rdbuf() const; (since C++11) Returns pointer to the underlying raw file device object. Parameters (none). Return value Pointer to the underlying raw file device. Example

std::basic_fstream

Defined in header <fstream> template< class CharT, class Traits = std::char_traits<CharT> > class basic_fstream : public std::basic_iostream<CharT, Traits> The class template basic_fstream implements high-level input/output operations on file based streams. It interfaces a file-based streambuffer (std::basic_filebuf) with the high-level interface of (std::basic_iostream). A typical implementation of std::basic_fstream holds only one non-derived d

std::basic_fstream::is_open

bool is_open(); (until C++11) bool is_open() const; (since C++11) Checks if the file stream has an associated file. Effectively calls rdbuf()->is_open(). Parameters (none). Return value true if the file stream has an associated file, false otherwise. Example #include <string> #include <fstream> #include <iostream> int main() { std::string filename = "some_file"; std::fstream fs(filename, std::ios::in); std::cout << std::boola

std::basic_fstream::close

void close(); Closes the associated file. Effectively calls rdbuf()->close(). If an error occurs during operation, setstate(failbit) is called. Parameters (none). Return value (none). Notes This function is called by the destructor of basic_fstream when the stream object goes out of scope and is not usually invoked directly. Example #include <string> #include <fstream> #include <iostream> int main() { std::fstream f1("example1", std::ios::out),

std::basic_fstream::basic_fstream

basic_fstream(); (1) explicit basic_fstream( const char* filename, ios_base::openmode mode = ios_base::in|ios_base::out ); (2) explicit basic_fstream( const string& filename, ios_base::openmode mode = ios_base::in|ios_base::out ); (3) (since C++11) basic_fstream( basic_fstream&& other ); (4) (since C++11) basic_fstream( const basic_fstream& rhs) = delete; (5) (since C++11) Constructs

std::basic_filebuf::uflow

protected: virtual int_type uflow() Behaves like the underflow(), except that if underflow() succeeds (does not return Traits::eof()), then advances the next pointer for the get area. In other words, consumes one of the characters obtained by underflow(). Parameters (none). Return value The value of the character that was read and consumed in case of success, or Traits::eof() in case of failure. Example See also uflow [virtual] reads characters from the associated inpu

std::basic_filebuf::sync

protected: virtual int sync() If a put area exists (e.g. the file was opened for writing), calls overflow() to write all pending output to the file, then flushes the file as if by calling std::fflush. If a get area exists (e.g. the file was opened for reading), the effect is implementation-defined. Typical implementation may empty out the get area and move the current file position back by the corresponding number of bytes. Parameters (none). Return value ​0​ in case of success, -

std::basic_filebuf::underflow

protected: virtual int_type underflow() Reads more data into the input area. Behaves like the base class std::basic_streambuf::underflow, except that to read the data from the associated character sequence (the file) into the get area, first reads the bytes from the file into a temporary buffer (allocated as large as necessary), then uses std::codecvt::in of the imbued locale to convert the external (typically, multibyte) representation to the internal form which is then used to populat

std::basic_filebuf::seekpos

protected: virtual pos_type seekpos( pos_type sp, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out ); Repositions the file pointer, if possible, to the position indicated by sp. If the associated file is not open (is_open()==false), fails immediately. If the file is open for writing, first writes the put area and any unshift sequences required by the currently imbued locale, using overflow(). Then repositions the file pointer, as if by cal