名稱空間
變體
操作

std::is_error_code_enum<std::io_errc>

來自 cppreference.com
< cpp‎ | io‎ | io errc
定義於標頭檔案 <ios>
template<>
struct is_error_code_enum<std::io_errc> : public std::true_type {};
(C++11 起)

std::is_error_code_enum 的特化告知其他庫元件,std::io_errc 型別的值是持有錯誤碼的列舉,這使得它們可以隱式轉換並賦值給 std::error_code 型別的物件。

目錄

繼承自 std::integral_constant

成員常量

value
[靜態]
true
(public static 成員常量)

成員函式

operator bool
將物件轉換為 bool,返回 value
(公開成員函式)
operator()
(C++14)
返回 value
(公開成員函式)

成員型別

型別 定義
value_type bool
型別 std::integral_constant<bool, value>

[編輯] 示例

e.code()std::io_errc::stream 之間的比較能夠編譯,因為 std::is_error_code_enum<std::io_errc>::value == true

#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";
        if (e.code() == std::io_errc::stream)
            std::cout << "The error code is std::io_errc::stream\n";
    }
}

輸出

Caught an ios_base::failure.
The error code is std::io_errc::stream

[編輯] 參閱

將一個類標識為 error_code 列舉
(類模板) [編輯]
儲存平臺相關錯誤碼
(類) [編輯]
(C++11)
I/O 流錯誤碼
(列舉) [編輯]