std::basic_filebuf<CharT,Traits>:: operator=
From cppreference.net
<
cpp
|
io
|
basic filebuf
|
std::
basic_filebuf
&
operator
=
(
std::
basic_filebuf
&&
rhs
)
;
|
(1) | (C++11 起) |
|
std::
basic_filebuf
&
operator
=
(
const
std::
basic_filebuf
&
rhs
)
=
delete
;
|
(2) | |
赋值另一个
basic_filebuf
对象。
1)
首先调用
close()
关闭关联文件,然后将
rhs
的内容移动到
*
this
:包括输出与输入缓冲区、关联文件、区域设置、打开模式、is_open 标志及其他所有状态。移动操作完成后,
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
对象
(公开成员函数) |