命名空间
变体
操作

标准库头文件 <ios>

来自 cppreference.cn
< cpp‎ | 头文件
 
 
标准库头文件
算法
<algorithm>
<numeric>
字符串
<cctype>
<cstring>
<cuchar> (C++11)
<cwchar>
<cwctype>
<string_view> (C++17)
<string>
文本处理
<clocale>
<codecvt> (C++11/17/26*)
<locale>
<regex> (C++11)
<text_encoding> (C++26)   
数值
<cfenv> (C++11)
<cmath>
<complex>
<linalg> (C++26)
<numbers> (C++20)
<random> (C++11)
<simd> (C++26)
<valarray>
时间
<chrono> (C++11)
<ctime>
C 兼容性
<ccomplex> (C++11/17/20*)
<ciso646> (直到 C++20)
<cstdalign> (C++11/17/20*)
<cstdbool> (C++11/17/20*)
<ctgmath> (C++11/17/20*)
 

此头文件是 输入/输出 库的一部分。

目录

包含

输入/输出库中所有类的前向声明[编辑]

管理格式化标志和输入/输出异常
(类) [编辑]
管理任意流缓冲区
(类模板) [编辑]
std::ios std::basic_ios<char> (类型定义)
std::wios std::basic_ios<wchar_t> (类型定义)
表示流或文件中的绝对位置
(类模板) [编辑]
(C++11)
IO 流错误代码
(枚举) [编辑]
扩展类型特征 std::is_error_code_enum 以识别 iostream 错误代码
(类模板特化) [编辑]
表示相对文件/流位置(距 fpos 的偏移量),足以表示任何文件大小
(类型定义) [编辑]
表示 I/O 操作中传输的字符数或 I/O 缓冲区的大小
(类型定义) [编辑]

函数

识别 iostream 错误类别
(函数) [编辑]
构造 iostream 错误代码
(函数) [编辑]
构造 iostream 错误条件
(函数) [编辑]
在布尔值的文本和数字表示之间切换
(函数) [编辑]
控制是否使用前缀来指示数字基数
(函数) [编辑]
控制浮点数表示中是否始终包含小数点
(函数) [编辑]
控制非负数是否使用 + 符号
(函数) [编辑]
控制输入时是否跳过前导空格
(函数) [编辑]
控制某些输出格式是否使用大写字符
(函数) [编辑]
控制每次操作后是否刷新输出
(函数) [编辑]
设置填充字符的放置位置
(函数) [编辑]
更改用于整数 I/O 的基数
(函数) [编辑]
更改用于浮点数 I/O 的格式
(函数) [编辑]

[编辑] 概要

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

[编辑] std::ios_base

namespace std {
  class ios_base {
  public:
    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);
 
  protected:
    ios_base();
 
  private:
    static int index;           // exposition only
    long*  iarray;              // exposition only
    void** parray;              // exposition only
  };
}

[编辑] std::ios_base::failure

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

[编辑] std::ios_base::Init

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

[编辑] 类模板 std::fpos

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

[编辑] 类模板 std::basic_ios

namespace std {
  template<class CharT, class Traits = char_traits<CharT>>
  class basic_ios : public ios_base {
  public:
    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;
 
  protected:
    basic_ios();
    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);
  };
}

[编辑] 缺陷报告

以下行为变更缺陷报告被追溯应用于先前发布的 C++ 标准。

DR 应用于 已发布行为 正确行为
LWG 35 C++98 unitbufnounitbuf 的原型在概要中缺失 已添加
LWG 78 C++98 ios_base::register_callback 的参数 fn 的类型
在概要中错误地指定为 event_call_back
已更正为
event_callback