std::basic_filebuf<CharT,Traits>::operator=

From cppreference.com
< cpp‎ | io‎ | basic filebuf
 
 
Input/output library
I/O manipulators
C-style I/O
Buffers
(deprecated in C++98)
Streams
Abstractions
File I/O
String I/O
Array I/O
(deprecated in C++98)
(deprecated in C++98)
(deprecated in C++98)
Synchronized Output
Types
Error category interface
(C++11)
 
 
(since C++11)
std::basic_filebuf& operator=( const std::basic_filebuf& rhs ) = delete;

Assigns another basic_filebuf object.

1) 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.
2) The copy assignment operator is deleted; basic_filebuf is not CopyAssignable.

Parameters

rhs - another basic_filebuf that will be moved from

Return value

*this

Example

#include <fstream>
#include <string>
#include <iostream>
 
int main()
{
 
    std::ifstream fin("test.in"); // read-only
    std::ofstream fout("test.out"); // write-only
 
    std::string s;
    getline(fin, s);
    std::cout << s << '\n'; // output
 
    *fin.rdbuf() = std::move(*fout.rdbuf());
 
    getline(fin, s);
    std::cout << s << '\n'; // empty line
 
    std::cout << std::boolalpha << fout.is_open() << '\n'; // prints "false"
 
}


See also

constructs a basic_filebuf object
(public member function)
(C++11)
swaps two basic_filebuf objects
(public member function)