标准库标头 <ios>

出自cppreference.com
< cpp‎ | header


 
 
標準庫頭
通用工具
<any> (C++17)
<bitset>
<bit> (C++20)
<charconv> (C++17)
<expected> (C++23)
<format> (C++20)
<functional>
<optional> (C++17)
<stdbit.h> (C++26)
<tuple> (C++11)
<typeindex> (C++11)
<utility>
<variant> (C++17)
容器
<array> (C++11)
<deque>
<flat_map> (C++23)
<flat_set> (C++23)
<forward_list> (C++11)
<hive> (C++26)
<inplace_vector> (C++26)   
<list>
<map>
<mdspan> (C++23)
<queue>
<set>
<span> (C++20)
<stack>
<unordered_map> (C++11)
<unordered_set> (C++11)
<vector>
迭代器
<iterator>
範圍
<generator> (C++23)
<ranges> (C++20)
 

此頭文件是輸入/輸出庫的一部分。

目錄

包含

輸入/輸出庫中所有類的前置聲明[編輯]

管理格式化標誌和輸入/輸出異常
(類) [編輯]
管理任意流緩衝
(類模板) [編輯]
std::ios std::basic_ios<char> (typedef)
std::wios std::basic_ios<wchar_t> (typedef)
表示流或文件中的絕對位置
(類模板) [編輯]
(C++11)
輸入/輸出流的錯誤碼
(枚舉) [編輯]
擴充類型特徵 std::is_error_code_enum 以鑒別 iostream 錯誤碼
(類模板特化) [編輯]
表示相對的文件/流位置(距 fpos 的偏移),足以表示任何文件大小
(typedef) [編輯]
表示一次輸入/輸出操作中轉移的字元數或輸入/輸出緩衝區的大小
(typedef) [編輯]

函數

鑒別 iostream 錯誤類別
(函數) [編輯]
構造一個 iostream 錯誤碼
(函數) [編輯]
構造一個 iostream error_condition
(函數) [編輯]
在布爾值的文本和數值表示間切換
(函數) [編輯]
控制是否使用前綴指示數值基數
(函數) [編輯]
控制浮點數表示是否始終包含小數點
(函數) [編輯]
控制是否將 + 號與非負數一同使用
(函數) [編輯]
控制是否跳過輸入上的前導空白符
(函數) [編輯]
控制一些輸出操作是否使用大寫字母
(函數) [編輯]
控制是否每次操作後沖洗輸出
(函數) [編輯]
設置填充字元的布置
(函數) [編輯]
更改用於整數輸入/輸出的基數
(函數) [編輯]
更改用數於浮點數 I/O 的格式化
(函數) [編輯]

[編輯] 概要

#include <iosfwd>
 
namespace std {
  using streamoff  = /* 由实现定义 */;
  using streamsize = /* 由实现定义 */;
  template<class StateT> class fpos;
 
  class ios_base;
  template<class CharT, class Traits = char_traits<CharT>>
    class basic_ios;
 
  // 操纵符
  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);
 
  // 调整域
  ios_base& internal   (ios_base& str);
  ios_base& left       (ios_base& str);
  ios_base& right      (ios_base& str);
 
  // 基底域
  ios_base& dec        (ios_base& str);
  ios_base& hex        (ios_base& str);
  ios_base& oct        (ios_base& str);
 
  // 浮点域
  ios_base& fixed      (ios_base& str);
  ios_base& scientific (ios_base& str);
  ios_base& hexfloat   (ios_base& str);
  ios_base& defaultfloat(ios_base& str);
 
  // 错误报告
  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;              // 见描述
 
    // fmtflags
    using fmtflags = /*位掩码类型-1*/;
    static constexpr fmtflags boolalpha = /* 未指明 */;
    static constexpr fmtflags dec = /* 未指明 */;
    static constexpr fmtflags fixed = /* 未指明 */;
    static constexpr fmtflags hex = /* 未指明 */;
    static constexpr fmtflags internal = /* 未指明 */;
    static constexpr fmtflags left = /* 未指明 */;
    static constexpr fmtflags oct = /* 未指明 */;
    static constexpr fmtflags right = /* 未指明 */;
    static constexpr fmtflags scientific = /* 未指明 */;
    static constexpr fmtflags showbase = /* 未指明 */;
    static constexpr fmtflags showpoint = /* 未指明 */;
    static constexpr fmtflags showpos = /* 未指明 */;
    static constexpr fmtflags skipws = /* 未指明 */;
    static constexpr fmtflags unitbuf = /* 未指明 */;
    static constexpr fmtflags uppercase = /* 未指明 */;
    static constexpr fmtflags adjustfield = /* 见描述 */;
    static constexpr fmtflags basefield = /* 见描述 */;
    static constexpr fmtflags floatfield = /* 见描述 */;
 
    // iostate
    using iostate = /*位掩码类型-2*/;
    static constexpr iostate badbit = /* 未指明 */;
    static constexpr iostate eofbit = /* 未指明 */;
    static constexpr iostate failbit = /* 未指明 */;
    static constexpr iostate goodbit = /* 见描述 */;
 
    // openmode
    using openmode = /*位掩码类型-3*/;
    static constexpr openmode app = /* 未指明 */;
    static constexpr openmode ate = /* 未指明 */;
    static constexpr openmode binary = /* 未指明 */;
    static constexpr openmode in = /* 未指明 */;
    static constexpr openmode out = /* 未指明 */;
    static constexpr openmode trunc = /* 未指明 */;
    static constexpr openmode noreplace = /* 未指明 */
 
    // seekdir
    using seekdir = /*位掩码类型-4*/;
    static constexpr seekdir beg = /* 未指明 */;
    static constexpr seekdir cur = /* 未指明 */;
    static constexpr seekdir end = /* 未指明 */;
 
    class Init;
 
    // fmtflags 状态
    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);
 
    // 本地环境
    locale imbue(const locale& loc);
    locale getloc() const;
 
    // 存储
    static int xalloc();
    long&  iword(int idx);
    void*& pword(int idx);
 
    // 析构函数
    virtual ~ios_base();
 
    // 回调
    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;           // 仅用于阐释
    long*  iarray;              // 仅用于阐释
    void** parray;              // 仅用于阐释
  };
}

[編輯] 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;        // 仅用于阐释
  };
}

[編輯] 類模板 std::fpos

namespace std {
  template<class StateT> class fpos {
  public:
    // 成员
    StateT state() const;
    void state(stateT);
  private;
    StateT st;                  // 仅用于阐释
  };
}

[編輯] 類模板 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;
 
    // 标志函数
    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);
 
    // 构造函数/析构函数
    explicit basic_ios(basic_streambuf<CharT, Traits>* sb);
    virtual ~basic_ios();
 
    // 成员
    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++ 標準。

缺陷報告 應用於 出版時的行為 正確行為
LWG 35 C++98 概要中缺失了 unitbufnounitbuf 的原型 已補充
LWG 78 C++98 概要中 ios_base::register_callback
形參 fn 的類型被誤寫為 event_call_back
改正為 event_callback