Namespaces
Variants

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

From cppreference.net
(1) (C++11 起)
std:: basic_stringbuf & operator = ( const std:: basic_stringbuf & rhs ) = delete ;
(2)
1) 移动赋值运算符:将 rhs 的内容移动至 * this 。移动后, * this 将拥有 rhs 先前持有的关联字符串、打开模式、区域设置及所有其他状态。 std::basic_streambuf * this 中的六个指针保证与被移动的 rhs 中的对应指针不同(除非该指针为空)。
2) 复制赋值运算符被删除; basic_stringbuf 不满足 CopyAssignable 要求。

目录

参数

rhs - 另一个将被移出的 basic_stringbuf

返回值

* this

示例

#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";
}

输出:

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

参见

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