名稱空間
變體
操作

std::system_category

來自 cppreference.com
< cpp‎ | 錯誤
定義於標頭檔案 <system_error>
const std::error_category& system_category() noexcept;
(C++11 起)

獲取作業系統報告錯誤的靜態錯誤類別物件的引用。該物件必須重寫虛擬函式 std::error_category::name() 以返回指向字串 "system" 的指標。它還必須重寫虛擬函式 std::error_category::default_error_condition() 以將與 POSIX errno 值匹配的錯誤碼對映到 std::generic_category

目錄

[編輯] 引數

(無)

[編輯] 返回值

對靜態物件的引用,該靜態物件的執行時型別未指定,派生自 std::error_category

[編輯] 注意

在 Windows 上,system_category() 通常將一些 Windows 錯誤碼 對映到 POSIX 錯誤碼。在 POSIX 上,system_category() 除了名稱之外,通常等同於 std::generic_category()

[編輯] 示例

#include <iomanip>
#include <iostream>
#include <string>
#include <system_error>
 
int main()
{
    for (int const code : {EDOM, 10001})
    {
        const std::error_condition econd =
            std::system_category().default_error_condition(code);
 
        std::cout << "Category: " << econd.category().name() << '\n'
                  << "Value:    " << econd.value() << '\n'
                  << "Message:  " << econd.message() << "\n\n";
    }
}

可能的輸出

Category: generic
Value:    33
Message:  Numerical argument out of domain
 
Category: system
Value:    10001
Message:  Unknown error 10001

[編輯] 參閱

識別通用錯誤類別
(函式) [編輯]
(C++11)
std::error_condition 列舉,列出所有標準 <cerrno> 宏常量
(類) [編輯]