std::basic_ostream::basic_ostream
来自cppreference.com
< cpp | io | basic ostream
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
explicit basic_ostream( std::basic_streambuf<CharT, Traits>* sb ); |
(1) | |
protected: basic_ostream( const basic_ostream& rhs ) = delete; |
(2) | |
protected: basic_ostream( basic_ostream&& rhs ); |
(3) | (C++11 起) |
构建
2) basic_ostream
对象,分配初始值的基类通过调用basic_ios::init(sb).原文:
Constructs the
basic_ostream
object, assigning initial values to the base class by calling basic_ios::init(sb).拷贝构造函数是受保护的,将被删除。输出流是不可复制的.
3) 原文:
The copy constructor is protected, and is deleted. Output streams are not copyable.
此举构造函数使用
basic_ios<CharT, Traits>::move(rhs)
,将所有basic_ios成员,除了为rdbuf()
,,从rhs
到*this
。这一举措的构造函数是受保护的,它被称为move构造函数的的活动输出流类std::basic_ofstreamstd::basic_ostringstream,哪知道如何正确地移动相关的streambuffer的.原文:
The move constructor 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 output stream classes std::basic_ofstream and std::basic_ostringstream, which know how to correctly move the associated streambuffer.[编辑] 参数
sb | - | 作为输出序列streambuffer使用
原文: streambuffer to use as output sequence |
rhs | - | basic_ostream要进行初始化
|
[编辑] 示例
#include <sstream> #include <utility> #include <iostream> int main() { // std::ostream myout(std::cout); // ERROR: copy ctor is deleted std::ostream myout(std::cout.rdbuf()); // OK: shares buffer with cout // std::ostream s2(std::move(std::ostringstream() << 7.1)); // ERROR: move constructor // is protected std::ostringstream s2(std::move(std::ostringstream() << 7.1)); // OK: move ctor called // through the derived class myout << s2.str() << '\n'; }
输出:
7.1