std::make_error_code(std::io_errc)
來自 cppreference.com
定義於標頭檔案 <ios> |
||
std::error_code make_error_code( std::io_errc e ) noexcept; |
(C++11 起) | |
構造一個 std::error_code 物件,其值為 std::io_errc 型別,如同透過 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++ 標準。
缺陷報告 | 應用於 | 釋出時的行為 | 正確的行為 |
---|---|---|---|
LWG 2087 | C++11 | make_error_code(io_errc) 未宣告為 noexcept |
宣告為 noexcept |
[編輯] 參閱
(C++11) |
儲存平臺相關錯誤碼 (類) |
(C++11) |
I/O 流錯誤碼 (列舉) |
(C++11) |
為 errc 列舉 e 建立錯誤碼值(函式) |
構造一個 future 錯誤程式碼 (函式) |