Namespaces
Variants
Views
Actions

std::basic_stringbuf::operator=

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

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

<tr class="t-dcl ">

<td >
std::basic_stringbuf& operator=( std::basic_stringbuf&& rhs );
</td>

<td class="t-dcl-nopad"> </td> <td > (since C++11) </td> </tr> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td class="t-dcl-nopad">
std::basic_stringbuf& operator=( const std::basic_stringbuf& rhs ) = delete;
</td>

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

1) Move assignment operator: Moves the contents of rhs into *this. After the move, lhs has the associated string, the open mode, the locale, and all other state formerly held by rhs. The six pointers of std::basic_streambuf in lhs are guaranteed to be different from the corresponding pointers in the moved-from rhs unless null.
2) The copy assignment operator is deleted; basic_stringbuf is not CopyAssignable.

Contents

Parameters

rhs - another basic_stringbuf that will be moved from

Return value

*this

Example

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

Output:

Before move, one = "one" two = "two"
Before move, one = "two" two = ""

See also

Template:cpp/io/basic stringbuf/dcl list constructor