public member function
std::<ios> <iostream>

std::basic_ios::operator bool

operator void*() const;
explicit operator bool() const;
評估流
返回錯誤標誌是否已設定(failbitbadbit)。

請注意,此函式返回的結果與成員函式 good 不同,而是與成員函式 fail 的結果相反。

如果設定了其中一個錯誤標誌,則函式返回一個空指標,否則返回其他值。
如果設定了其中一個錯誤標誌,則函式返回false,否則返回true

引數



返回值

如果設定了 failbitbadbit 之一,則返回空指標。否則返回其他值。
如果 failbitbadbit 均未設定,則返回true
否則返回 false

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// evaluating a stream
#include <iostream>     // std::cerr
#include <fstream>      // std::ifstream

int main () {
  std::ifstream is;
  is.open ("test.txt");
  if (is) {
    // read file
  }
  else {
    std::cerr << "Error opening 'test.txt'\n";
  }
  return 0;
}

資料競爭

訪問流物件。
併發訪問同一個流物件可能導致資料爭用。

異常安全

強保證: 如果丟擲異常,流不會發生任何改變。

另見