function template
<fstream>

std::swap (basic_ofstream)

void swap (ofstream& x, ofstream& y);
Swap output file streams
Exchanges the values of the ofstream objects x and y.

這是通用演算法 swap 的一個過載,其行為如同x.swap(y)被呼叫。

引數

x,y
ofstream objects to swap.

返回值



示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// swapping ofstream objects
#include <fstream>      // std::ofstream

int main () {
  std::ofstream foo;
  std::ofstream bar ("test.txt");

  swap(foo,bar);

  foo << "lorem ipsum";

  foo.close();

  return 0;
}

資料競爭

兩個物件,xy,都會被修改。

異常安全

無異常保證:此成員函式從不丟擲異常。

另見