std::basic_fstream<CharT,Traits>::basic_fstream (3) - Linux Manuals
std::basic_fstream<CharT,Traits>::basic_fstream: std::basic_fstream<CharT,Traits>::basic_fstream
NAME
std::basic_fstream<CharT,Traits>::basic_fstream - std::basic_fstream<CharT,Traits>::basic_fstream
Synopsis
basic_fstream(); (1)
explicit basic_fstream( const char* filename, (2)
std::ios_base::openmode mode = ios_base::in|ios_base::out );
explicit basic_fstream( const std::filesystem::path::value_type* filename, (3) (since C++17)
std::ios_base::openmode mode = ios_base::in|ios_base::out );
explicit basic_fstream( const std::string& filename, (4) (since C++11)
std::ios_base::openmode mode = ios_base::in|ios_base::out );
explicit basic_fstream( const std::filesystem::path& filename, (5) (since C++17)
std::ios_base::openmode mode = ios_base::in|ios_base::out );
basic_fstream( basic_fstream&& other ); (6) (since C++11)
basic_fstream( const basic_fstream& rhs) = delete; (7) (since C++11)
Constructs new file stream.
1) Default constructor: constructs a stream that is not associated with a file: default-constructs the std::basic_filebuf and constructs the base with the pointer to this default-constructed std::basic_filebuf member.
2-3) First, performs the same steps as the default constructor, then associates the stream with a file by calling rdbuf()->open(filename, mode) (see std::basic_filebuf::open for the details on the effects of that call). If the open() call returns a null pointer, sets setstate(failbit).
Overload (3) is only provided if std::filesystem::path::value_type is not char.
(since C++17)
4-5) Same as basic_fstream(filename.c_str(), mode).
6) Move constructor. First, move-constructs the base class from other (which does not affect the rdbuf() pointer), then move-constructs the std::basic_filebuf member, then calls this->set_rdbuf() to install the new basic_filebuf as the rdbuf() pointer in the base class.
7) The copy-constructor is deleted: this class is not copyable.
Parameters
filename - the name of the file to be opened
mode - binary open in binary_mode
other - another file stream to use as source
Example
// Run this code
See also
open (public member function)
open (public member function of std::basic_filebuf<CharT,Traits>)
set_rdbuf (protected member function)
constructor (public member function of std::basic_iostream<CharT,Traits>)