std::basic_stringbuf<CharT,Traits,Allocator>::swap

void swap( std::basic_stringbuf& rhs )
(since C++11)

Swaps the state and the contents of *this and rhs.

Parameters

rhs - another basic_stringbuf

Return value

(none).

Notes

This function is called automatically when swapping std::stringstream objects, it is rarely necessary to call it directly.

Example

#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";
}

Output:

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

See also

constructs a basic_stringbuf object
(public member function)
(C++11)
swaps two string streams
(public member function of std::basic_stringstream<CharT,Traits,Allocator>)

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/io/basic_stringbuf/swap