它交換fstream
對象x
和y
的值。
聲明
下麵是fstream:: swap的聲明。
C++11
template <class charT, class traits>
void swap (basic_fstream<charT,traits>& x, basic_fstream<charT,traits>& y);
參數
x
,y
− 與basic_ostream
對象類型相同(即,具有相同的範本參數,charT
和traits
)。
示例
下麵的例子解釋了 fstream
中的 swap
函數。
#include <fstream>
int main () {
std::fstream foo;
std::fstream bar ("test.txt");
swap(foo,bar);
foo << "zaixian tutorials";
foo.close();
return 0;
}
上一篇:
basic_ios::openmode
下一篇:
ios_base::seekdir