名前空間
変種

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

提供: cppreference.com
< cpp‎ | io‎ | basic ostream
2012年10月30日 (火) 16:27時点におけるP12 (トーク | 投稿記録)による版

 
 
入出力ライブラリ
入出力マニピュレータ
Cスタイルの入出力
バッファ
(C++98で非推奨)
ストリーム
抽象
ファイル入出力
文字列入出力
配列入出力
(C++98で非推奨)
(C++98で非推奨)
(C++98で非推奨)
同期化出力
エラーカテゴリインタフェース
(C++11)
 
 
protected:
basic_istream& operator=( const basic_ostream& rhs ) = delete;
(1)
protected:
basic_ostream& operator=( basic_ostream&& rhs );
(2) (C++11以上)

1) The copy assignment operator is protected, and is deleted. Output streams are not CopyAssignable.

2) The move assignment operator exchanges all data members of the base class, except for rdbuf(), with rhs, as if by calling swap(*rhs). This move assignment operator is protected: it is only called by the move assignment operators of the derived movable output stream classes std::basic_ofstream and std::basic_ostringstream, which know how to correctly move-assign the associated streambuffers.

パラメータ

rhs - the basic_ostream object from which to assign to *this

#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 derived
    std::cout << s.str() << '\n';
}

出力:

42