std::basic_filebuf<CharT,Traits>::operator=
来自cppreference.com
< cpp | io | basic filebuf
std::basic_filebuf& operator=(std::basic_filebuf&& rhs ); | (1) | (C++11 起) |
std::basic_filebuf& operator=(conststd::basic_filebuf& rhs )= delete; | (2) | |
赋值另一 basic_filebuf
对象。
1) 首先调用 close() 关闭关联文件,然后移动 rhs 的内容到 *this 中:获取与放置缓冲区、本地环境、打开模式、打开标志及任何其他状态。移动后,rhs 不与文件关联且 rhs.is_open()==false。
目录 |
[编辑]参数
rhs | - | 将被移动的另一 basic_filebuf |
[编辑]返回值
*this
[编辑]示例
运行此代码
#include <cassert>#include <fstream>#include <iostream>#include <string> int main(){std::ofstream{"test.in"}<<"test\n";// 通过临时对象进行写入std::ifstream fin("test.in");// 只读流std::ofstream fout("test.out");// 只写流 std::string s;std::getline(fin, s);std::cout<<"s = ["<< s <<"]\n";// s 包含 "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 为空输入}
输出:
s = [test] s = []
[编辑]参阅
构造 basic_filebuf 对象 (公开成员函数) | |
(C++11) | 交换两个 basic_filebuf 对象 (公开成员函数) |