# std::iostream_category

> C++ Atlas: `cppatlas.com/w/cpp/io/iostream_category` | Source: https://en.cppreference.com/w/cpp/io/iostream_category | Domain: Input/output | Standards: 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".

## Official Specification Summary (cppreference)

```cpp
// Defined in header <ios>
const std::error_category& iostream_category() noexcept; // (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`.

### Parameters

(none)

### Return value

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

### Example

```cpp
#include <fstream>
#include <iostream>

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

    }
}
```

Possible output:

```text
Caught an ios_base::failure.
Error code: 1 (unspecified iostream_category error)
Error category: iostream
```

### Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

| DR | Applied to | Behavior as published | Correct behavior |
| --- | --- | --- | --- |
| LWG 2087 | C++11 | `iostream_category` was not declared `noexcept` | declared `noexcept` |

### See also

- [`failure`](https://en.cppreference.com/w/cpp/io/ios_base/failure): stream exception (public member class of `std::ios_base`)
- [`io_errc`](https://en.cppreference.com/w/cpp/io/io_errc) (C++11): the IO stream error codes (enum)

---
Attribution: content from https://en.cppreference.com/w/cpp/io/iostream_category (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.