std::basic_istream<CharT,Traits>:: operator=
From cppreference.net
<
cpp
|
io
|
basic istream
C++
Input/output library
| I/O manipulators | ||||
| Print functions (C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(C++20)
|
||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
| Synchronized Output | ||||
|
(C++20)
|
||||
| Types | ||||
| Error category interface | ||||
|
(C++11)
|
||||
|
(C++11)
|
std::basic_istream
| Global objects | ||||
| Member functions | ||||
|
basic_istream::operator=
(C++11)
|
||||
| Formatted input | ||||
| Unformatted input | ||||
| Positioning | ||||
| Miscellaneous | ||||
|
(C++11)
|
||||
| Member classes | ||||
| Non-member functions | ||||
|
protected
:
basic_istream & operator = ( const basic_istream & rhs ) = delete ; |
(1) | |
|
protected
:
basic_istream & operator = ( basic_istream && rhs ) ; |
(2) | (C++11以降) |
1)
コピー代入演算子は protected で、削除されています。入力ストリームは CopyAssignable ではありません。
2)
ムーブ代入演算子は、
gcount()
の値と基底クラスのすべてのデータメンバ(
rdbuf()
を除く)を
rhs
と交換する。これは
swap
(
*
rhs
)
を呼び出すかのように動作する。このムーブ代入演算子はprotectedである:これは派生したムーブ可能な入力ストリームクラスである
std::basic_ifstream
および
std::basic_istringstream
のムーブ代入演算子によってのみ呼び出され、これらのクラスは関連するストリームバッファを正しくムーブ代入する方法を知っている。
パラメータ
| rhs | - | 代入元のbasic_istreamオブジェクト * this |
例
このコードを実行
#include <iostream> #include <sstream> int main() { std::istringstream s1; s1 = std::istringstream("test"); // OK // std::cin = std::istringstream("test"); // ERROR: 'operator=' is protected }