Namespaces
Variants
Views
Actions

std::basic_filebuf::operator=

From cppreference.com
< cpp‎ | io‎ | basic filebuf
Revision as of 22:39, 2 November 2012 by P12bot (Talk | contribs)

Template:ddcl list begin <tr class="t-dcl ">

<td >
std::basic_filebuf& operator=( std::basic_filebuf&& rhs );
</td>

<td class="t-dcl-nopad"> </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td class="t-dcl-nopad">
std::basic_filebuf& operator=( const std::basic_filebuf& rhs ) = delete;
</td>

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

1) First calls Template:rlpf 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.

Contents

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

Template:cpp/io/basic filebuf/dcl list basic filebufTemplate:cpp/io/basic filebuf/dcl list swap