命名空间
变体
操作

std::basic_filebuf<CharT,Traits>::operator=

来自 cppreference.cn
< cpp‎ | io‎ | basic filebuf
 
 
 
 
(1) (始于 C++11)
std::basic_filebuf& operator=( const std::basic_filebuf& rhs ) = delete;
(2)

赋值另一个 basic_filebuf 对象。

1) 首先调用 close() 关闭关联的文件,然后将 rhs 的内容移动到 *this:放置和获取缓冲区、关联的文件、locale、openmode、is_open 标志以及任何其他状态。移动后,rhs 不再与文件关联,并且 rhs.is_open() == false
2) 复制赋值运算符被删除;basic_filebuf 不是 CopyAssignable

目录

[编辑] 参数

rhs - 另一个 basic_filebuf,其内容将被移动

[编辑] 返回值

*this

[编辑] 示例

#include <cassert>
#include <fstream>
#include <iostream>
#include <string>
 
int main()
{
    std::ofstream{"test.in"} << "test\n"; // writes via a temporary object
    std::ifstream fin("test.in"); // read-only stream
    std::ofstream fout("test.out"); // write-only stream
 
    std::string s;
    std::getline(fin, s);
    std::cout << "s = [" << s << "]\n"; // s contains "test"
 
    assert(fout.is_open());
    *fin.rdbuf() = std::move(*fout.rdbuf());
    assert(!fout.is_open());
 
    std::getline(fin, s);
    std::cout << "s = [" << s << "]\n"; // s is empty input
}

输出

s = [test]
s = []

[编辑] 参见

构造一个 basic_filebuf 对象
(公共成员函数) [编辑]
(C++11)
交换两个 basic_filebuf 对象
(公共成员函数) [编辑]