std::basic_istream::basic_istream
来自cppreference.com
< cpp | io | basic istream
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
explicit basic_istream( std::basic_streambuf<CharT,Traits>* sb); |
(1) | |
protected: basic_istream( const basic_istream& rhs ) = delete; |
(2) | |
protected: basic_istream( basic_istream&& rhs ); |
(3) | (C++11 起) |
,分配初始值
2) basic_istream
通过调用基类的构造basic_ios::init(sb)对象。被初始化为零的值gcount()
.原文:
Constructs the
basic_istream
object, assigning initial values to the base class by calling basic_ios::init(sb). The value of gcount()
is initialized to zero.拷贝构造函数是受保护的,将被删除。输入流是不可复制的.
3) 原文:
The copy constructor is protected, and is deleted. Input streams are not copyable.
此举构造函数的值复制
gcount()
从rhs
的gcount的(),设定值的右边为零,并使用basic_ios<charT, traits>::move(rhs)
,将所有basic_ios的成员,除为rdbuf()
,从rhs
到*this
。这一举动的构造函数是受保护的,它被称为可移动的输入流类的构造函数的移动std::basic_ifstream和std::basic_istringstream,哪知道如何正确地移动相关的streambuffer的.原文:
The move constructor copies the value of
gcount()
from rhs
, sets the gcount() value of rhs to zero, and uses basic_ios<charT, traits>::move(rhs)
to move all basic_ios members, except for the rdbuf()
, from rhs
into *this
. This move constructor is protected: it is called by the move constructors of movable input stream classes std::basic_ifstream and std::basic_istringstream, which know how to correctly move the associated streambuffer.[编辑] 参数
sb | - | streambuffer使用的基础设备
原文: streambuffer to use as underlying device |
[编辑] 示例
#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