fstream::swap()函數
它用於在x
和*this
之間交換所有的內部數據。
聲明
下麵是fstream::swap
的聲明。
C++11
void swap (basic_fstream& x);
參數
x −另一個相同類型的basic_ostream
對象(即,具有相同的範本參數:charT
和traits
)。
示例
下麵的例子解釋了fstream::swap()
函數用法。
#include <fstream>
int main () {
std::fstream foo;
std::fstream bar ("test.txt");
foo.swap(bar);
foo << "cpp fstream swap";
foo.close();
return 0;
}