名前空間
変種
操作

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

提供: cppreference.com
< cpp‎ | io‎ | basic ostream
 
 
 
 
protected:
basic_ostream& operator=(const basic_ostream& rhs )= delete;
(1)
protected:
basic_ostream& operator=( basic_ostream&& rhs );
(2) (C++11以上)

1) コピー代入演算子は protected であり、削除されています。 出力ストリームはコピー代入可能ではありません。

2) ムーブ代入演算子は、 swap(*rhs) を呼んだかのように、 rdbuf() を除いた基底クラスのすべてのデータメンバを rhs と交換します。 このムーブ代入演算子は protected です。 紐付けられているストリームバッファを正しくムーブ代入する方法を知っているムーブ可能な派生出力ストリームクラス std::basic_ofstream および std::basic_ostringstream によってのみ呼ばれます。

[編集]引数

rhs - *this に代入する basic_ostream オブジェクト

[編集]

#include <sstream>#include <utility>#include <iostream>int main(){std::ostringstream s;// std::cout = s; // ERROR: copy assignment operator is deleted// std::cout = std::move(s); // ERROR: move assignment operator is protected s = std::move(std::ostringstream()<<42);// OK, moved through derivedstd::cout<< s.str()<<'\n';}

出力:

42
close