首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::system_category

Defined in header <system_error>

const std::error_category& system_category();

(since C++11)

获取对操作系统报告的错误的静态错误类别对象的引用。对象需要重写虚拟函数。std::error_category::name()返回指向字符串的指针"system"它还需要覆盖虚拟函数。std::error_category::default_error_condition()映射与POSIX匹配的错误代码errno值到std::generic_category...

参数

%280%29

返回值

派生为未指定运行时类型的静态对象的引用。std::error_category...

例外

noexcept规格:

noexcept

二次

代码语言:javascript
复制
#include <iostream>
#include <system_error>
#include <iomanip>
#include <string>
 
int main()
{
    std::error_condition econd = std::system_category().default_error_condition(EDOM);
    std::cout << "Category: " << econd.category().name() << '\n'
              << "Value: " << econd.value() << '\n'
              << "Message: " << econd.message() << '\n';
 
    econd = std::system_category().default_error_condition(10001);
    std::cout << "Category: " << econd.category().name() << '\n'
              << "Value: " << econd.value() << '\n'
              << "Message: " << econd.message() << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
Category: generic
Value: 33
Message: Numerical argument out of domain
Category: system
Value: 10001
Message: Unknown error 10001

二次

另见

generic_category (C++11)

identifies the generic error category (function)

errc (C++11)

the std::error_condition enumeration listing all standard <cerrno> macro constants (class)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券