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

< cpp‎ | io‎ | basic stringbuf
(1) (C++11 起)
std::basic_stringbuf& operator=( const std::basic_stringbuf& rhs ) = delete;
(2)
1) 移动赋值运算符:移动 rhs 的内容到 *this 中。移动后 *this 拥有 rhs 之前保有的关联 string 、打开模式、本地环境和所有其他状态。保证 *thisstd::basic_streambuf 的六个指针有别于被移动的 rhs 的对应指针,除非它们为空。
2) 复制赋值运算符被删除; basic_stringbuf可复制赋值 (CopyAssignable)

参数

rhs - 将被移动的另一 basic_stringbuf

返回值

*this

示例

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

输出:

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

参阅

构造一个 basic_stringbuf 对象
(公开成员函数)