- fstream[meta header]
- std[meta namespace]
- basic_filebuf[meta class]
- function[meta id-type]
- cpp11[meta cpp]
basic_filebuf& operator=(const basic_filebuf&) = delete; // (1) C++11
basic_filebuf& operator=(basic_filebuf&& rhs); // (2) C++11
- (1) : コピー代入。この演算子は
delete定義されており、basic_filebufオブジェクトはコピーできない
- (2) : ムーブ代入。
rhsが管理していたファイルの所有権を*thisに移動する
- (2) :
*thisは、rhsからムーブ構築された場合と同じ観測可能な状態を持つ。詳細はコンストラクタを参照
#include <iostream>
#include <fstream>
#include <utility>
int main()
{
{
std::filebuf out;
out.open("test.txt", std::ios_base::out);
out.sputn("Hello", 5);
}
std::filebuf a;
a.open("test.txt", std::ios_base::in);
std::filebuf b;
b = std::move(a); // aが開いていたファイルをbに移動する
std::cout << std::boolalpha
<< a.is_open() << ' '
<< b.is_open() << std::endl;
std::cout << static_cast<char>(b.sbumpc()) << std::endl;
}
- std::filebuf[link /reference/fstream/basic_filebuf.md]
- out.open[link open.md]
- a.open[link open.md]
- a.is_open()[link is_open.md]
- b.is_open()[link is_open.md]
- out.sputn[link /reference/streambuf/basic_streambuf/sputn.md]
- b.sbumpc()[link /reference/streambuf/basic_streambuf/sbumpc.md]
- std::move[link /reference/utility/move.md]