std::iostream_category
來自 cppreference.com
定義於標頭檔案 <ios> |
||
const std::error_category& iostream_category() noexcept; |
(C++11 起) | |
獲取 iostream 錯誤的靜態錯誤類別物件的引用。該物件需要重寫虛擬函式 error_category::name() 以返回指向字串 "iostream" 的指標。它用於識別型別為 std::ios_base::failure 的異常中提供的錯誤程式碼。
目錄 |
[編輯] 引數
(無)
[編輯] 返回值
對靜態物件的引用,該靜態物件的執行時型別未指定,派生自 std::error_category。
[編輯] 示例
執行此程式碼
#include <fstream> #include <iostream> int main() { std::ifstream f("doesn't exist"); try { f.exceptions(f.failbit); } catch (const std::ios_base::failure& e) { std::cout << "Caught an ios_base::failure.\n" << "Error code: " << e.code().value() << " (" << e.code().message() << ")\n" << "Error category: " << e.code().category().name() << '\n'; } }
可能的輸出
Caught an ios_base::failure. Error code: 1 (unspecified iostream_category error) Error category: iostream
[編輯] 缺陷報告
下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。
缺陷報告 | 應用於 | 釋出時的行為 | 正確的行為 |
---|---|---|---|
LWG 2087 | C++11 | iostream_category 未宣告為 noexcept |
宣告為 noexcept |
[編輯] 另請參閱
流異常 ( std::ios_base 的公共成員類) | |
(C++11) |
I/O 流錯誤碼 (列舉) |