首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::basic_filebuf::swap

void swap( std::basic_filebuf& rhs );

?

(since C++11)

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

参数

rhs

-

another basic_filebuf

返回值

%280%29

注记

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

二次

代码语言:javascript
复制
#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)

代码语言:txt
复制
 ? cppreference.com

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com