std::basic_stringbuf::swap - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::basic_stringbuf::swap

From cppreference.com
< cpp‎ | io‎ | basic stringbuf

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

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

### [edit] Parameters

rhs | - | another `basic_stringbuf`

### [edit] Return value

(none)

### [edit] Notes

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

### [edit] Example

Run this code

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

### [edit] See also

(constructor) | constructs a basic_stringbuf object (public member function) [edit]
swap (C++11) | swaps two string streams (public member function of `std::basic_stringstream`) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/io/basic_stringbuf/swap&oldid=62742"