std::basic_filebuf<CharT,Traits>::operator= - cppreference.com (original) (raw)
Assigns another basic_filebuf object.
First calls close() to close the associated file, then moves the contents of rhs into *this: the put and get buffers, the associated file, the locale, the openmode, the is_open flag, and any other state. After the move, rhs is not associated with a file and rhs.is_open() == false.
The copy assignment operator is deleted;
basic_filebufis not CopyAssignable.
[edit] Parameters
| rhs | - | another basic_filebuf that will be moved from |
|---|
[edit] Return value
*this
[edit] Example
#include #include #include #include int main() { std::ofstream{"test.in"} << "test\n"; // writes via a temporary object std::ifstream fin("test.in"); // read-only stream std::ofstream fout("test.out"); // write-only stream std::string s; std::getline(fin, s); std::cout << "s = [" << s << "]\n"; // s contains "test" assert(fout.is_open()); *fin.rdbuf() = std::move(*fout.rdbuf()); assert(!fout.is_open()); std::getline(fin, s); std::cout << "s = [" << s << "]\n"; // s is empty input }
Output:
[edit] See also
| | constructs a basic_filebuf object (public member function) [edit] | | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | | swaps two basic_filebuf objects (public member function) [edit] |