std::basic_ostream::swap
来自cppreference.com
< cpp | io | basic ostream
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
protected: void swap(basic_ostream& rhs); |
(C++11 起) | |
呼叫basic_ios::swap(rhs)交换基类的所有数据成员,除了rdbuf(),*this和
rhs
之间。该交换功能的保护:它被称为交换功能的交换输出流类std::basic_ofstreamstd::basic_ostringstream,哪知道如何正确地交换相关的streambuffers,.原文:
Calls basic_ios::swap(rhs) to swap all data members of the base class, except for rdbuf(), between *this and
rhs
. This swap function is protected: it is called by the swap functions of the swappable output stream classes std::basic_ofstream and std::basic_ostringstream, which know how to correctly swap the associated streambuffers.[编辑] 参数
rhs | - | 相同类型的一个basic_ostream交换
原文: a basic_ostream of the same type to swap with |
[编辑] 示例
#include <sstream> #include <iostream> #include <utility> int main() { std::ostringstream s1("hello"); std::ostringstream s2("bye"); s1.swap(s2); // OK, ostringstream has a public swap() std::swap(s1, s2); // OK, calls s1.swap(s2) // std::cout.swap(s2); // ERROR: swap is a protected member std::cout << s1.str() << '\n'; }
输出:
hello