std::make_error_condition(std::io_errc)
来自 cppreference.cn
定义于头文件 <ios> |
||
std::error_condition make_error_condition( std::io_errc e ) noexcept; |
(始于 C++11) | |
从 std::io_errc 类型的值构造 std::error_condition 对象,如同通过 return std::error_condition(static_cast<int>(e), std::iostream_category()) 一样。
目录 |
[编辑] 参数
e | - | 错误代码编号 |
[编辑] 返回值
类型为 std::error_condition 的值,持有来自 e 的错误代码编号,并与错误类别 "iostream" 关联。
[编辑] 示例
运行此代码
#include <iostream> #include <system_error> int main() { std::error_condition ec = std::make_error_condition(std::io_errc::stream); std::cout << "error condition for io_errc::stream has value " << ec.value() << "\nand message \"" << ec.message() << "\"\n"; }
输出
error condition for io_errc::stream has value 1 and message "unspecified iostream_category error"
[编辑] 缺陷报告
以下行为变更缺陷报告被追溯应用于先前发布的 C++ 标准。
DR | 应用于 | 已发布行为 | 正确行为 |
---|---|---|---|
LWG 2087 | C++11 | make_error_condition(io_errc) 未声明为 noexcept |
声明为 noexcept |
[编辑] 参见
(C++11) |
持有可移植的错误代码 (类) |
(C++11) |
IO 流错误代码 (枚举) |