在线文档教程
C++
输入/输出 | Input/output

std::basic_filebuf::swap

性病:基本[医]filebuf::交换

void swap( std::basic_filebuf& rhs (since C++11)

交换状态和内容*thisrhs...

参数

rhs-another basic_filebuf

返回值

%280%29

注记

此函数在交换时自动调用。std::fstream对象时,很少有必要直接调用它。

二次

#include <fstream> #include <string> #include <iostream> int main() { std::ifstream fin("test.in" // read-only std::ofstream fout("test.out" // write-only std::string s; getline(fin, s std::cout << s << '\n'; // outputs the first line of test.in fin.rdbuf()->swap(*fout.rdbuf() //swap the underlying buffers getline(fin, s // fails: cannot read from a write-only filebuf std::cout << s << '\n'; // prints empty line }

二次

另见

operator= (C++11)assigns a basic_filebuf object (public member function)
std::swap(std::basic_filebuf) (C++11)specializes the std::swap algorithm (function template)
swap (C++11)swaps two file streams (public member function of std::basic_fstream)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/io/basic[医]文件/交换