std::system_category
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <system_error> 中定义
|
||
const std::error_category& system_category(); |
(C++11 起) | |
获得参考的静态误差类对象由操作系统报告的错误。需要重写虚函数error_category::name()返回一个指针,指向的字符串"system"的对象。它也需要重写虚函数error_category::default_error_condition()的错误代码映射匹配POSIXerrno值std::generic_category.
原文:
Obtains a reference to the static error category object for errors reported by the operating system. The object is required to override the virtual function error_category::name() to return a pointer to the string "system". It is also required to override the virtual function error_category::default_error_condition() to map the error codes that match POSIX errno values to std::generic_category.
目录 |
[编辑] 参数
(无)
[编辑] 返回值
未指定的运行时类型,来自std::error_category的静态对象的参考.
原文:
A reference to the static object of unspecified runtime type, derived from std::error_category.
[编辑] 例外
[编辑] 示例
#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'; }
输出:
Category: generic Value: 33 Message: Numerical argument out of domain Category: system Value: 10001 Message: Unknown error 10001
[编辑] 另请参阅
(C++11) |
标识通用的错误类别 原文: identifies the generic error category (函数) |
(C++11) |
std::error_condition列出所有标准 <cerrno> 宏常量枚举原文: the std::error_condition enumeration listing all standard <cerrno> macro constants(类) |