Namespaces
Variants
Views
Actions

std::io_errc

From cppreference.com
< cpp‎ | io
Revision as of 08:46, 10 May 2013 by P12 (Talk | contribs)

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <ios>
</td>

<td></td> <td></td> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
enum class io_errc;
</td>

<td class="t-dcl-nopad"> </td> <td > (since C++11) </td> </tr> Template:ddcl list end

The scoped enumeration std::io_errc defines the error codes reported by I/O streams in std::ios_base::failure exception objects. Only one error code (std::io_errc::stream) is required, although the implementation may define additional error codes. Because the appropriate specialization of std::is_error_code_enum is provided, values of type std::io_errc are implicitly convertible to std::error_code.

Contents

Member constants

Enumeration constant Value
stream 1

Helper classes

extends the type trait std::is_error_code_enum to identify iostream error codes
(class template)

Non-member functions

constructs an iostream error code
(function)
constructs an iostream error_condition
(function)

Example

#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";
        if(e.code() == std::io_errc::stream)
            std::cout << "The error code is std::io_errc::stream\n";
    }
}

Output:

Caught an ios_base::failure.
The error code is std::io_errc::stream

See also

Template:cpp/error/dcl list error codeTemplate:cpp/error/dcl list error conditionTemplate:cpp/io/ios base/dcl list failure