std::basic_filebuf<CharT,Traits>::swap
提供: cppreference.com
<tbody>
</tbody>
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-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
}
関連項目
(C++11) |
basic_filebuf オブジェクトを代入します (パブリックメンバ関数) |
| std::swap アルゴリズムの特殊化 (関数テンプレート) | |
(C++11) |
2つのファイルストリームを入れ替えます ( std::basic_fstream<CharT,Traits>のパブリックメンバ関数)
|