std::make_error_code(std::io_errc)
来自 cppreference.cn
定义于头文件 <ios> |
||
std::error_code make_error_code( std::io_errc e ) noexcept; |
(自 C++11 起) | |
从 std::io_errc 类型的值构造 std::error_code 对象,如同通过 return std::error_code(static_cast<int>(e), std::iostream_category())。
此函数由 std::error_code 的构造函数以 std::io_errc 参数调用。
目录 |
[编辑] 参数
e | - | 错误代码编号 |
[编辑] 返回值
类型为 std::error_code 的值,持有来自 e 的错误代码编号,并与错误类别 "iostream" 关联。
[编辑] 示例
运行此代码
#include <iostream> #include <system_error> int main() { std::error_code ec = std::make_error_code(std::io_errc::stream); // This works because of the overloaded method // and the is_error_code_enum specialization. ec = std::io_errc::stream; std::cout << "Error code from io_errc::stream has category " << ec.category().name() << '\n'; }
输出
Error code from io_errc::stream has category iostream
[编辑] 缺陷报告
以下行为变更缺陷报告被追溯应用到先前发布的 C++ 标准。
DR | 应用于 | 已发布行为 | 正确行为 |
---|---|---|---|
LWG 2087 | C++11 | make_error_code(io_errc) 未声明为 noexcept |
声明为 noexcept |
[编辑] 参见
(C++11) |
持有平台相关的错误代码 (类) |
(C++11) |
IO 流错误代码 (枚举) |
(C++11) |
为 errc 枚举 e 创建错误代码值(函数) |
构造 future 错误代码 (函数) |