Namespaces
Variants

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

From cppreference.net
(1) (C++11以降)
std:: basic_filebuf & operator = ( const std:: basic_filebuf & rhs ) = delete ;
(2)

別の basic_filebuf オブジェクトを割り当てます。

1) まず close() を呼び出して関連付けられたファイルを閉じ、その後 rhs の内容を * this に移動します:出力バッファと入力バッファ、関連付けられたファイル、ロケール、オープンモード、is_openフラグ、およびその他の状態。移動後、 rhs はファイルに関連付けられておらず、 rhs. is_open ( ) == false となります。
2) コピー代入演算子は削除されています; basic_filebuf CopyAssignable ではありません。

目次

パラメータ

rhs - 移動元となる別の basic_filebuf

戻り値

* this

#include <cassert>
#include <fstream>
#include <iostream>
#include <string>
int main()
{
    std::ofstream{"test.in"} << "test\n"; // 一時オブジェクトを介して書き込み
    std::ifstream fin("test.in"); // 読み取り専用ストリーム
    std::ofstream fout("test.out"); // 書き込み専用ストリーム
    std::string s;
    std::getline(fin, s);
    std::cout << "s = [" << s << "]\n"; // sは"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は空の入力
}

出力:

s = [test]
s = []

関連項目

basic_filebuf オブジェクトを構築する
(public member function)
(C++11)
2つの basic_filebuf オブジェクトを交換する
(public member function)