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

Assigns another basic_filebuf object.

# Declarations

std::basic_filebuf& operator=( std::basic_filebuf&& rhs );

(since C++11)

std::basic_filebuf& operator=( const std::basic_filebuf& rhs ) = delete;

# Parameters

# Return value

*this

# Example

#include <cassert>
#include <fstream>
#include <iostream>
#include <string>
 
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
}

# See also