在线文档教程
C++
输入/输出 | Input/output

std::ios_base::failure

科技促进发展:监督办[医]基础::失败

Defined in header
class failure;

全班std::ios_base::failure定义输入/输出库中的函数在失败时抛出的异常对象。

std::ios_base::failure的成员类可以定义为std::ios_base或者作为同义词%28tydurif%29用于另一个具有同等功能的类。%28自C++17%29。

Inheritance diagram.(until C++11)
Inheritance diagram.(since C++11)

成员函数

(constructor)constructs the exception object (public member function)

科技促进发展:监督办[医]*失败:::失败

explicit failure( const std::string& message (until C++11)
explicit failure( const std::string& message, const std::error_code& ec = std::io_errc::stream (since C++11)
explicit failure( const char* message, const std::error_code& ec = std::io_errc::stream (since C++11)

使用message作为解释字符串,以后可以使用what()...

参数

message-explanatory string

继承自STD:系统[医]误差

成员函数

codereturns error code (public member function of std::system_error)
what virtualreturns explanatory string (virtual public member function of std::system_error)

继承自STD::运行时[医]误差

继承自STD:例外

成员函数

(destructor) virtualdestructs the exception object (virtual public member function of std::exception)
what virtualreturns an explanatory string (virtual public member function of std::exception)

二次

#include <iostream> #include <fstream> int main() { std::ifstream f("doesn't exist" try { f.exceptions(f.failbit } catch (const std::ios_base::failure& e) { std::cout << "Caught an ios_base::failure.\n" << "Explanatory string: " << e.what() << '\n' << "Error code: " << e.code() << '\n'; } }

二次

产出:

二次

Caught an ios_base::failure. Explanatory string: ios_base::clear: unspecified iostream_category error Error code: iostream:1

二次

另见

io_errc (C++11)the IO stream error codes (enum)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/io/IOS[医]基座/失效