Namespaces
Variants
Views
Actions

std::basic_stringbuf::swap

From cppreference.com
< cpp‎ | io‎ | basic stringbuf
Revision as of 19:44, 2 November 2012 by P12bot (Talk | contribs)

Template:ddcl list begin <tr class="t-dcl ">

<td >
void swap( std::basic_stringbuf& rhs )
</td>

<td class="t-dcl-nopad"> </td> <td > (since C++11) </td> </tr> Template:ddcl list end

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

Contents

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

Template:cpp/io/basic stringbuf/dcl list constructorTemplate:cpp/io/basic stringstream/dcl list swap