函式
<ios> <iostream>

std::iostream_category

const error_category& iostream_category();
const error_category& iostream_category() noexcept;
返回 iostream 類別
返回一個指向具有以下特徵的 `error_category` 型別靜態物件的引用。

與此類別關聯的是描述與列舉型別 io_errc 相對應的錯誤的 error_condition 物件。何為其中一個對應的關係取決於作業系統和具體的庫實現。

引數



返回值

iostream error_category 物件的引用。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// io_errc example
// iostream_category example
#include <iostream>     // std::cin, std::cerr, std::ios,
                        // std::iostream_category
int main () {
  std::cin.exceptions (std::ios::failbit|std::ios::badbit);
  try {
    std::cin.rdbuf(nullptr);    // throws
  } catch (std::ios::failure& e) {
    std::cerr << "failure caught: ";
    if ( e.code().category() == std::iostream_category() )
      std::cerr << "error code of the iostream category\n"; 
    else
      std::cerr << "error code of some other category\n";
  }
  return 0;
}

可能的輸出

failure caught: error code of the iostream category


異常安全

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

另見