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

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

# Declarations

void swap( basic_stringbuf& rhs );

(since C++11) (until C++20)

void swap( basic_stringbuf& rhs ) noexcept(/* see below */);

(since C++20)

# Parameters

# Return value

(none)

# Notes

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

# Example

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

# See also