# std::basic_stringbuf<CharT,Traits,Allocator>::operator=

> C++ Atlas: `cppatlas.com/w/cpp/io/basic_stringbuf/operator=` | Source: https://en.cppreference.com/w/cpp/io/basic_stringbuf/operator= | Domain: Input/output | Standards: C++11

## Official Specification Summary (cppreference)

```cpp
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, `*this` 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 `*this` 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*.

### Parameters

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

### Return value

`*this`

### Example

```cpp
#include <iostream>
#include <sstream>
#include <string>

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 << "After move, one = \"" << one.str() << '"'
              << " two = \"" << two.str() << "\"\n";
}
```

Output:

```text
Before move, one = "one" two = "two"
After move, one = "two" two = ""
```

### See also

- [(constructor)](https://en.cppreference.com/w/cpp/io/basic_stringbuf/basic_stringbuf): constructs a `basic_stringbuf` object (public member function)

---
Attribution: content from https://en.cppreference.com/w/cpp/io/basic_stringbuf/operator= (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.