std::basic_filebuf<CharT,Traits>::swap
From cppreference.com
< cpp | io | basic filebuf
| void swap( std::basic_filebuf& rhs ); |
(C++11以降) | |
*this と rhs の状態と内容を交換します。
目次 |
[edit] パラメータ
| rhs | - | 別の basic_filebuf |
[edit] 戻り値
(なし)
[edit] 備考
この関数は、std::fstream オブジェクトを交換する際に自動的に呼び出されるため、通常は直接呼び出す必要はありません。
[edit] 例
このコードを実行
#include <fstream> #include <iostream> #include <string> 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 }
[edit] 関連項目
| (C++11) |
basic_filebuf オブジェクトを代入します(public member function) |
| std::swap アルゴリズムを特殊化する (関数テンプレート) | |
| (C++11) |
2つのファイルストリームをスワップする ( std::basic_fstream<CharT,Traits> の public メンバ関数) |