function template
<fstream>

std::swap (ifstream)

void swap (ifstream& x, ifstream& y);
交換輸入檔案流
交換 ifstream 物件 xy 的值。

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

引數

x,y
要交換的 ifstream 物件。

返回值



示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// swapping ifstream objects
#include <iostream>     // std::cout
#include <fstream>      // std::ifstream

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

  swap (foo,bar);

  char c = foo.get();

  while (foo.good()) {
    std::cout << c;
    c = foo.get();
  }

  foo.close();

  return 0;
}

資料競爭

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

異常安全

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

另見