std::basic_stringbuf::swap

来自cppreference.com
< cpp‎ | io‎ | basic stringbuf
void swap( std::basic_stringbuf& rhs )
(C++11 起)

交换 *thisrhs 的状态与内容。

目录

[编辑] 参数

rhs - 另一 basic_stringbuf

[编辑] 返回值

(无)

[编辑] 注意

交换 std::stringstream 对象时自动调用此函数,很少需要直接调用它。

[编辑] 示例

#include <sstream>
#include <string>
#include <iostream>
 
int main()
{
 
    std::istringstream one("one");
    std::ostringstream two("two");
 
    std::cout << "Before swap, one = \"" << one.str() << '"'
              << " two = \"" << two.str() << "\"\n";
 
    *one.rdbuf()->swap(*two.rdbuf());
 
    std::cout << "Before swap, one = \"" << one.str() << '"'
              << " two = \"" << two.str() << "\"\n";
}

输出:

Before swap, one = "one" two = "two"
Before swap, one = "two" two = "one"

[编辑] 参阅

构造一个 basic_stringbuf 对象
(公开成员函数) [编辑]
(C++11)
交换两个字符串流
(std::basic_stringstream 的公开成员函数) [编辑]