std::basic_filebuf<CharT,Traits>::swap
提供: cppreference.com
< cpp | io | basic filebuf
void swap(std::basic_filebuf& rhs ); | (C++11以上) | |
*this と rhs
の状態と内容を入れ替えます。
目次 |
[編集]引数
rhs | - | 別の basic_filebuf |
[編集]戻り値
(なし)
[編集]ノート
この関数は std::fstream オブジェクトを swap するとき自動的に呼ばれます。 直接呼ぶ必要はほとんどありません。
[編集]例
Run this code
#include <fstream>#include <string>#include <iostream> int main(){std::ifstream fin("test.in");// read-onlystd::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 filebufstd::cout<< s <<'\n';// prints empty line}
[編集]関連項目
(C++11) | basic_filebuf オブジェクトを代入します (パブリックメンバ関数) |
std::swap アルゴリズムの特殊化 (関数テンプレート) | |
(C++11) | 2つのファイルストリームを入れ替えます ( std::basic_fstream<CharT,Traits> のパブリックメンバ関数) |