Standard library header <ios>

< cpp‎ | header
Standard library headers
Language support
<concepts> (C++20)
<system_error> (C++11)

Memory management
<memory_resource> (C++17)  
<type_traits> (C++11)
<ratio> (C++11)
General utilities
<tuple> (C++11)
<optional> (C++17)
<variant> (C++17)
<any> (C++17)
<debugging> (C++26)
<expected> (C++23)
<charconv> (C++17)
<format> (C++20)
<bit> (C++20)

<cuchar> (C++11)

<flat_set> (C++23)
<span> (C++20)
<mdspan> (C++23)
<inplace_vector> (C++26)
<ranges> (C++20)
<generator> (C++23)
<cfenv> (C++11)
<linalg> (C++26)
<numbers> (C++20)

<chrono> (C++11)
<codecvt> (C++11/17/26*)
<text_encoding> (C++26)
<filesystem> (C++17)
<cinttypes> (C++11)
<strstream> (C++98/26*)
Regular expressions
<regex> (C++11)
Concurrency support
<stop_token> (C++20)
<thread> (C++11)
<atomic> (C++11)
<rcu> (C++26)
<stdatomic.h> (C++23)
<mutex> (C++11)
<shared_mutex> (C++14)

<condition_variable> (C++11)  
<semaphore> (C++20)
<latch> (C++20)

<barrier> (C++20)
<future> (C++11)
<hazard_pointer> (C++26)

C compatibility
<cstdbool> (C++11/17/20*)  
<ccomplex> (C++11/17/20*)
<ctgmath> (C++11/17/20*)

<cstdalign> (C++11/17/20*)

<ciso646> (until C++20)


This header is part of the Input/Output library.



Forward declarations of all classes in the input/output library[edit]


manages formatting flags and input/output exceptions
(class) [edit]
manages an arbitrary stream buffer
(class template) [edit]
std::ios std::basic_ios<char> (typedef)
std::wios std::basic_ios<wchar_t> (typedef)
represents absolute position in a stream or a file
(class template) [edit]
the IO stream error codes
(enum) [edit]
extends the type trait std::is_error_code_enum to identify iostream error codes
(class template specialization) [edit]
represents relative file/stream position (offset from fpos), sufficient to represent any file size
(typedef) [edit]
represents the number of characters transferred in an I/O operation or the size of an I/O buffer
(typedef) [edit]


identifies the iostream error category
(function) [edit]
constructs an iostream error code
(function) [edit]
constructs an iostream error condition
(function) [edit]
switches between textual and numeric representation of booleans
(function) [edit]
controls whether prefix is used to indicate numeric base
(function) [edit]
controls whether decimal point is always included in floating-point representation
(function) [edit]
controls whether the + sign used with non-negative numbers
(function) [edit]
controls whether leading whitespace is skipped on input
(function) [edit]
controls whether uppercase characters are used with some output formats
(function) [edit]
controls whether output is flushed after each operation
(function) [edit]
sets the placement of fill characters
(function) [edit]
changes the base used for integer I/O
(function) [edit]
changes formatting used for floating-point I/O
(function) [edit]

[edit] Synopsis

#include <iosfwd>
namespace std {
  using streamoff  = /* implementation-defined */;
  using streamsize = /* implementation-defined */;
  template<class StateT> class fpos;
  class ios_base;
  template<class CharT, class Traits = char_traits<CharT>>
    class basic_ios;
  // manipulators
  ios_base& boolalpha  (ios_base& str);
  ios_base& noboolalpha(ios_base& str);
  ios_base& showbase   (ios_base& str);
  ios_base& noshowbase (ios_base& str);
  ios_base& showpoint  (ios_base& str);
  ios_base& noshowpoint(ios_base& str);
  ios_base& showpos    (ios_base& str);
  ios_base& noshowpos  (ios_base& str);
  ios_base& skipws     (ios_base& str);
  ios_base& noskipws   (ios_base& str);
  ios_base& uppercase  (ios_base& str);
  ios_base& nouppercase(ios_base& str);
  ios_base& unitbuf    (ios_base& str);
  ios_base& nounitbuf  (ios_base& str);
  // adjustfield
  ios_base& internal   (ios_base& str);
  ios_base& left       (ios_base& str);
  ios_base& right      (ios_base& str);
  // basefield
  ios_base& dec        (ios_base& str);
  ios_base& hex        (ios_base& str);
  ios_base& oct        (ios_base& str);
  // floatfield
  ios_base& fixed      (ios_base& str);
  ios_base& scientific (ios_base& str);
  ios_base& hexfloat   (ios_base& str);
  ios_base& defaultfloat(ios_base& str);
  // error reporting
  enum class io_errc {
    stream = 1
  template<> struct is_error_code_enum<io_errc> : public true_type { };
  error_code make_error_code(io_errc e) noexcept;
  error_condition make_error_condition(io_errc e) noexcept;
  const error_category& iostream_category() noexcept;

[edit] Class std::ios_base

namespace std {
  class ios_base {
    class failure;              // see description
    // fmtflags
    using fmtflags = /*bitmask-type-1*/;
    static constexpr fmtflags boolalpha = /* unspecified */;
    static constexpr fmtflags dec = /* unspecified */;
    static constexpr fmtflags fixed = /* unspecified */;
    static constexpr fmtflags hex = /* unspecified */;
    static constexpr fmtflags internal = /* unspecified */;
    static constexpr fmtflags left = /* unspecified */;
    static constexpr fmtflags oct = /* unspecified */;
    static constexpr fmtflags right = /* unspecified */;
    static constexpr fmtflags scientific = /* unspecified */;
    static constexpr fmtflags showbase = /* unspecified */;
    static constexpr fmtflags showpoint = /* unspecified */;
    static constexpr fmtflags showpos = /* unspecified */;
    static constexpr fmtflags skipws = /* unspecified */;
    static constexpr fmtflags unitbuf = /* unspecified */;
    static constexpr fmtflags uppercase = /* unspecified */;
    static constexpr fmtflags adjustfield = /* see description */;
    static constexpr fmtflags basefield = /* see description */;
    static constexpr fmtflags floatfield = /* see description */;
    // iostate
    using iostate = /*bitmask-type-2*/;
    static constexpr iostate badbit = /* unspecified */;
    static constexpr iostate eofbit = /* unspecified */;
    static constexpr iostate failbit = /* unspecified */;
    static constexpr iostate goodbit = /* see description */;
    // openmode
    using openmode = /*bitmask-type-3*/;
    static constexpr openmode app = /* unspecified */;
    static constexpr openmode ate = /* unspecified */;
    static constexpr openmode binary = /* unspecified */;
    static constexpr openmode in = /* unspecified */;
    static constexpr openmode out = /* unspecified */;
    static constexpr openmode trunc = /* unspecified */;
    static constexpr openmode noreplace = /* unspecified */
    // seekdir
    using seekdir = /*bitmask-type-4*/;
    static constexpr seekdir beg = /* unspecified */;
    static constexpr seekdir cur = /* unspecified */;
    static constexpr seekdir end = /* unspecified */;
    class Init;
    // fmtflags state
    fmtflags flags() const;
    fmtflags flags(fmtflags fmtfl);
    fmtflags setf(fmtflags fmtfl);
    fmtflags setf(fmtflags fmtfl, fmtflags mask);
    void unsetf(fmtflags mask);
    streamsize precision() const;
    streamsize precision(streamsize prec);
    streamsize width() const;
    streamsize width(streamsize wide);
    // locales
    locale imbue(const locale& loc);
    locale getloc() const;
    // storage
    static int xalloc();
    long&  iword(int idx);
    void*& pword(int idx);
    // destructor
    virtual ~ios_base();
    // callbacks
    enum event { erase_event, imbue_event, copyfmt_event };
    using event_callback = void (*)(event, ios_base&, int idx);
    void register_callback(event_callback fn, int idx);
    ios_base(const ios_base&) = delete;
    ios_base& operator=(const ios_base&) = delete;
    static bool sync_with_stdio(bool sync = true);
    static int index;           // exposition only
    long*  iarray;              // exposition only
    void** parray;              // exposition only

[edit] Class std::ios_base::failure

namespace std {
  class ios_base::failure : public system_error {
    explicit failure(const string& msg, const error_code& ec = io_errc::stream);
    explicit failure(const char* msg, const error_code& ec = io_errc::stream);

[edit] Class std::ios_base::Init

namespace std {
  class ios_base::Init {
    Init(const Init&) = default;
    Init& operator=(const Init&) = default;
    static int init_cnt;        // exposition only

[edit] Class template std::fpos

namespace std {
  template<class StateT> class fpos {
    // members
    StateT state() const;
    void state(stateT);
    StateT st;                  // exposition only

[edit] Class template std::basic_ios

namespace std {
  template<class CharT, class Traits = char_traits<CharT>>
  class basic_ios : public ios_base {
    using char_type   = CharT;
    using int_type    = typename Traits::int_type;
    using pos_type    = typename Traits::pos_type;
    using off_type    = typename Traits::off_type;
    using traits_type = Traits;
    // flags functions
    explicit operator bool() const;
    bool operator!() const;
    iostate rdstate() const;
    void clear(iostate state = goodbit);
    void setstate(iostate state);
    bool good() const;
    bool eof()  const;
    bool fail() const;
    bool bad()  const;
    iostate exceptions() const;
    void exceptions(iostate except);
    // constructor/destructor
    explicit basic_ios(basic_streambuf<CharT, Traits>* sb);
    virtual ~basic_ios();
    // members
    basic_ostream<CharT, Traits>* tie() const;
    basic_ostream<CharT, Traits>* tie(basic_ostream<CharT, Traits>* tiestr);
    basic_streambuf<CharT, Traits>* rdbuf() const;
    basic_streambuf<CharT, Traits>* rdbuf(basic_streambuf<CharT, Traits>* sb);
    basic_ios& copyfmt(const basic_ios& rhs);
    char_type fill() const;
    char_type fill(char_type ch);
    locale imbue(const locale& loc);
    char      narrow(char_type c, char dfault) const;
    char_type widen(char c) const;
    basic_ios(const basic_ios&) = delete;
    basic_ios& operator=(const basic_ios&) = delete;
    void init(basic_streambuf<CharT, Traits>* sb);
    void move(basic_ios& rhs);
    void move(basic_ios&& rhs);
    void swap(basic_ios& rhs) noexcept;
    void set_rdbuf(basic_streambuf<CharT, Traits>* sb);

[edit] 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 35 C++98 the prototypes of unitbuf and nounitbuf were missing in the synopsis added
LWG 78 C++98 the type of parameter fn of ios_base::register_callback
in the synopsis was misspecified as event_call_back
corrected to