std::io_errc(3)

๐Ÿ“ฆ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

๐Ÿ’– NAME ๐Ÿ’–

okay bestie, welcome to std::io_errc โ€” yes, the std::io_errc(3) page from the C++ Standard Libary manual ๐Ÿ’…

std::io_errc โ€” literally std::io_errc. That's the name, no cap ๐ŸŽ€


โœจ Synopsis โœจ

It lives in header <ios>:

enum class io_errc {

    stream = 1,          (since C++11)

};

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 ๐Ÿฆ‹

lowkey important: only std::io_errc::stream is guaranteed, but implementations are allowed to add extra codes. iykyk ๐Ÿ’€

๐Ÿงฎ Member constants ๐Ÿงฎ

  • Enumeration constant: stream
  • Value: 1

that's the whole lil' constants vibe, bestie โœจ


๐Ÿ› ๏ธ Non-member functions ๐Ÿ› ๏ธ

  • make_error_code(std::io_errc) โ€” constructs an iostream error code (function) (C++11) ๐Ÿซถ
  • make_error_condition(std::io_errc) โ€” constructs an iostream error condition (function) (C++11) ๐Ÿ’œ

๐Ÿงธ Helper classes ๐Ÿงธ

  • is_error_code_enum<std::io_errc> โ€” extends the type trait std::is_error_code_enum to identify iostream error codes (class template specialization) (C++11) ๐ŸŒธ

๐Ÿ“ Example ๐Ÿ“

run this code, bestie:

// Run this code

#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";
        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

ate, no crumbs ๐Ÿ‘‘


๐Ÿ‘€ See also ๐Ÿ‘€

  • error_code โ€” holds a platform-dependent error code (C++11) (class) ๐Ÿ”ฅ
  • error_condition โ€” holds a portable error code (C++11) (class) โญ
  • failure โ€” stream exception (public member class of std::ios_base) ๐Ÿ’–

mwah ๐Ÿ’‹ โ€” source: http://cppreference.com, date/version: 2024.06.10, for std::io_errc(3) in the C++ Standard Libary. periodt. ๐Ÿ’…

๐Ÿ“ฆ where this page comes from