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 new file stream.
std::basic_filebuf
and constructs the base with the pointer to this default-constructed std::basic_filebuf
member.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)
.basic_fstream(filename.c_str(), mode)
. 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.filename | - | the name of the file to be opened | ||||||||||||||
mode | - | specifies stream open mode. It is bitmask type, the following constants are defined:
|
||||||||||||||
other | - | another file stream to use as source |
#include <fstream> #include <utility> #include <string> int main() { std::fstream f0; std::fstream f1("test.bin", std::ios::binary); std::string name = "example.txt"; std::fstream f2(name); std::fstream f3(std::move(f1)); }
opens a file and associates it with the stream (public member function) |
|
opens a file and configures it as the associated character sequence (public member function of std::basic_filebuf ) |
|
replaces the rdbuf without clearing its error state (protected member function) |
|
constructs the object (public member function of std::basic_iostream ) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/io/basic_fstream/basic_fstream