std::basic_istream<CharT,Traits>::basic_istream
提供: cppreference.com
<tbody>
</tbody>
explicit basic_istream( std::basic_streambuf<CharT, Traits>* sb); |
(1) | |
protected: basic_istream( const basic_istream& rhs ) = delete; |
(2) | (C++11以上) |
protected: basic_istream( basic_istream&& rhs ); |
(3) | (C++11以上) |
1) basic_istream オブジェクトを構築し、 basic_ios::init(sb) を呼ぶことによって基底クラスの初期値を代入します。 gcount() の値はゼロに初期化されます。
2) コピーコンストラクタは protected であり、削除されています。 入力ストリームはコピー可能ではありません。
3) ムーブコンストラクタは gcount() の値を rhs からコピーし、 rhs の gcount() の値をゼロに設定し、 rdbuf() を除いたすべての basic_ios のメンバを rhs から *this にムーブするために basic_ios<CharT, Traits>::move(rhs) を使用します。 このムーブコンストラクタは protected です。 紐付けられているストリームバッファを正しくムーブする方法を知っているムーブ可能な入力ストリームクラス std::basic_ifstream および std::basic_istringstream のムーブコンストラクタによって呼ばれます。
引数
| sb | - | ベースとなるデバイスとして使用するストリームバッファ |
例
Run this code
#include <sstream>
#include <iostream>
int main()
{
std::istringstream s1("hello");
std::istream s2(s1.rdbuf()); // OK: s2 shares the buffer with s1
// std::istream s3(std::istringstream("test")); // ERROR: move constructor is protected
// std::istream s4(s2); // ERROR: copy constructor is deleted
std::istringstream s5(std::istringstream("world")); // OK: move ctor called by derived class
std::cout << s2.rdbuf() << ' ' << s5.rdbuf() << '\n';
}
出力:
hello world