##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::basic_stringbuf::operator=

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

std::basic_stringbuf& operator=( std::basic_stringbuf&& rhs ); | (1) | (since C++11)
std::basic_stringbuf& operator=( const std::basic_stringbuf& rhs ) = delete; | (2) |

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`.

### [edit] Parameters

rhs | - | another `basic_stringbuf` that will be moved from

### [edit] Return value

`*this`

### [edit] Example

Run this code

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

### [edit] See also

(constructor) | constructs a basic_stringbuf object (public member function) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/io/basic_stringbuf/operator%3D&oldid=62364"