首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::basic_stringbuf::swap

void swap( std::basic_stringbuf& rhs )

?

(since C++11)

交换状态和内容*thisrhs...

参数

rhs

-

another basic_stringbuf

返回值

%280%29

注记

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

二次

代码语言:javascript
复制
#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";
}

二次

产出:

二次

代码语言:javascript
复制
Before swap, one = "one" two = "two"
Before swap, one = "two" two = "one"

二次

另见

(constructor)

constructs a basic_stringbuf object (public member function)

swap (C++11)

swaps two string streams (public member function of std::basic_stringstream)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com