public member function
<fstream>

std::filebuf::is_open

bool is_open() const;
檢查檔案是否開啟
返回物件當前是否與檔案關聯(即是否開啟)。

如果先前呼叫成員函式 open 成功,並且自那時起沒有呼叫過成員函式 close,則函式返回 true

引數



返回值

如果檔案已開啟並與此檔案流緩衝區物件關聯,則為 true
否則返回 false

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// filebuf::is_open() example
#include <iostream>
#include <fstream>

int main () {
  std::ifstream is;
  std::filebuf * fb = is.rdbuf();
  fb->open ("test.txt",std::ios::in);

  if ( fb->is_open() )
    std::cout << "the file is open.\n";
  else
    std::cout << "the file is not open.\n";

  fb->close();

  return 0;
}

資料競爭

訪問 filebuf 物件。
同時訪問同一個檔案流緩衝區物件可能導致資料爭用。

異常安全

強保證: 如果丟擲異常,檔案流緩衝區將不會發生更改。

另見