std::make_error_condition(std::io_errc)
来自cppreference.com
在标头 <ios> 定义 | ||
std::error_condition make_error_condition(std::io_errc e )noexcept; | (C++11 起) | |
从 std::io_errc 类型的值构造一个 std::error_condition 对象,如同通过 returnstd::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<<"对于 io_errc::stream 的错误条件具有值 "<< ec.value()<<"\n和消息 \""<< ec.message()<<"\"\n";}
输出:
对于 io_errc::stream 的错误条件具有值 1 和消息 "unspecified iostream_category error"
[编辑]缺陷报告
下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。
缺陷报告 | 应用于 | 出版时的行为 | 正确行为 |
---|---|---|---|
LWG 2087 | C++11 | make_error_condition(io_errc) 未声明为 noexcept | 声明为 noexcept |
[编辑]参阅
(C++11) | 保有可移植的错误码 (类) |
(C++11) | 输入/输出流的错误码 (枚举) |