##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::iostream_category

From cppreference.com
< cpp‎ | io

Defined in header `<ios>` |  |
const std::error_category& iostream_category(); |  | (since C++11)

Obtains a reference to the static error category object for iostream errors. The object is required to override the virtual function error_category::name() to return a pointer to the string "iostream". It is used to identify error codes provided in the exceptions of type std::ios_base::failure.

### [edit] Parameters

(none)

### [edit] Return value

A reference to the static object of unspecified runtime type, derived from std::error_category.

### [edit] Exceptions

`noexcept` specification:
noexcept

### [edit] Example

Run this code

    #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"
                      << "Error category: " << e.code().category().name() << '\n';
        }
    }

Output:

    Caught an ios_base::failure.
    Error category: iostream

### [edit] See also

failure | stream exception (public member class of `std::ios_base`) [edit]
io_errc (C++11) | the IO stream error codes (enum) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/io/iostream_category&oldid=63326"