名稱空間
變體
操作

std::basic_ostream

來自 cppreference.com
< cpp‎ | io
 
 
 
 
定義於標頭檔案 <ostream>
template<

    class CharT,
    class Traits = std::char_traits<CharT>

> class basic_ostream : virtual public std::basic_ios<CharT, Traits>

類模板basic_ostream提供對字元流上高階輸出操作的支援。支援的操作包括格式化輸出(例如整數值)和非格式化輸出(例如原始字元和字元陣列)。此功能是根據basic_streambuf類提供的介面實現的,透過basic_ios基類訪問。在典型的實現中,basic_ostream沒有非繼承的資料成員。

cpp/io/ios basecpp/io/basic iosstd-basic ostream-inheritance.svg

繼承圖

提供了用於常見字元型別的幾個 typedef

定義於標頭檔案 <ostream>
型別 定義
std::ostream std::basic_ostream<char>
std::wostream std::basic_ostream<wchar_t>

目錄

[編輯] 全域性物件

標準庫提供六個全域性basic_ostream物件

定義於標頭檔案 <iostream>
寫入標準 C 輸出流 stdout
(全域性物件)[編輯]
寫入標準 C 錯誤流 stderr,無緩衝
(全域性物件)[編輯]
寫入標準 C 錯誤流 stderr
(全域性物件)[編輯]

[編輯] 成員型別

成員型別 定義
char_type CharT[編輯]
traits_type Traits;如果Traits::char_type不是CharT,則程式格式不正確。[編輯]
int_type Traits::int_type[編輯]
pos_type Traits::pos_type[編輯]
off_type Traits::off_type[編輯]

[編輯] 成員函式

構造物件
(public member function) [編輯]
[虛擬函式]
析構物件
(virtual public member function) [編輯]
(C++11)
從另一個basic_ostream移動賦值
(protected member function) [編輯]
格式化輸出
插入格式化資料
(public member function) [編輯]
非格式化輸出
插入一個字元
(public member function) [編輯]
插入字元塊
(public member function) [編輯]
定位
返回輸出位置指示器
(public member function) [編輯]
設定輸出位置指示器
(public member function) [編輯]
雜項
與底層儲存裝置同步
(public member function) [編輯]
(C++11)
交換流物件,除了關聯緩衝區
(protected member function) [編輯]

[編輯] 成員類

實現流為輸出操作準備的基本邏輯
(public member class) [編輯]

[編輯] 非成員函式

插入字元資料或插入到右值流中
(函式模板) [編輯]
輸出引數的格式化表示
(函式模板) [編輯]
輸出帶附加 '\n' 的引數格式化表示
(函式模板) [編輯]
使用型別擦除的引數表示執行 Unicode 感知輸出
(函式) [編輯]
使用型別擦除的引數表示輸出字元資料
(函式) [編輯]

繼承自 std::basic_ios

成員型別

成員型別 定義
char_type CharT
traits_type 特性
int_type Traits::int_type
pos_type Traits::pos_type
off_type Traits::off_type

成員函式

狀態函式
檢查是否沒有發生錯誤,即 I/O 操作可用
(std::basic_ios<CharT,Traits>的公共成員函式) [編輯]
檢查是否已到達檔案末尾
(std::basic_ios<CharT,Traits>的公共成員函式) [編輯]
檢查是否發生錯誤
(std::basic_ios<CharT,Traits>的公共成員函式) [編輯]
檢查是否發生不可恢復的錯誤
(std::basic_ios<CharT,Traits>的公共成員函式) [編輯]
檢查是否發生錯誤(fail() 的同義詞)
(std::basic_ios<CharT,Traits>的公共成員函式) [編輯]
檢查是否沒有發生錯誤(!fail() 的同義詞)
(std::basic_ios<CharT,Traits>的公共成員函式) [編輯]
返回狀態標誌
(std::basic_ios<CharT,Traits>的公共成員函式) [編輯]
設定狀態標誌
(std::basic_ios<CharT,Traits>的公共成員函式) [編輯]
修改狀態標誌
(std::basic_ios<CharT,Traits>的公共成員函式) [編輯]
格式化
複製格式化資訊
(std::basic_ios<CharT,Traits>的公共成員函式) [編輯]
管理填充字元
(std::basic_ios<CharT,Traits>的公共成員函式) [編輯]
雜項
管理異常掩碼
(std::basic_ios<CharT,Traits>的公共成員函式) [編輯]
設定區域設定
(std::basic_ios<CharT,Traits>的公共成員函式) [編輯]
管理關聯的流緩衝區
(std::basic_ios<CharT,Traits>的公共成員函式) [編輯]
管理繫結的流
(std::basic_ios<CharT,Traits>的公共成員函式) [編輯]
窄化字元
(std::basic_ios<CharT,Traits>的公共成員函式) [編輯]
寬化字元
(std::basic_ios<CharT,Traits>的公共成員函式) [編輯]

繼承自 std::ios_base

成員函式

格式化
管理格式標誌
(std::ios_base的公共成員函式) [編輯]
設定特定格式標誌
(std::ios_base的公共成員函式) [編輯]
清除特定格式標誌
(std::ios_base的公共成員函式) [編輯]
管理浮點運算的十進位制精度
(std::ios_base的公共成員函式) [編輯]
管理欄位寬度
(std::ios_base的公共成員函式) [編輯]
區域設定
設定區域設定
(std::ios_base的公共成員函式) [編輯]
返回當前區域設定
(std::ios_base的公共成員函式) [編輯]
內部可擴充套件陣列
[靜態]
返回一個程式範圍內的唯一整數,可安全用作 pword()iword() 的索引
(std::ios_base的公共靜態成員函式) [編輯]
如有必要,調整私有儲存的大小,並訪問給定索引處的 long 元素
(std::ios_base的公共成員函式) [編輯]
如有必要,調整私有儲存的大小,並訪問給定索引處的 void* 元素
(std::ios_base的公共成員函式) [編輯]
雜項
註冊事件回撥函式
(std::ios_base的公共成員函式) [編輯]
設定 C++ 和 C I/O 庫是否可互操作
(std::ios_base的公共靜態成員函式) [編輯]
成員類
流異常
(std::ios_base的公共成員類) [編輯]
初始化標準流物件
(std::ios_base的公共成員類) [編輯]

成員型別和常量

型別 解釋
流開啟模式型別

還定義了以下常量

常量 解釋[編輯]
app 每次寫入前定位到流的末尾[編輯]
二進位制 二進位制模式開啟[編輯]
in 為讀取開啟[編輯]
out 為寫入開啟[編輯]
trunc 開啟時丟棄流的內容[編輯]
ate 開啟後立即定位到流的末尾[編輯]
noreplace (C++23) 以獨佔模式開啟[編輯]

(型別定義) [編輯]
格式化標誌型別

還定義了以下常量

常量 解釋[編輯]
dec 使用十進位制基數進行整數 I/O:見 std::dec[編輯]
oct 使用八進位制基數進行整數 I/O:見 std::oct[編輯]
hex 使用十六進位制基數進行整數 I/O:見 std::hex[編輯]
basefield dec | oct | hex。用於掩碼操作[編輯]
left 左對齊(在右側新增填充字元):見 std::left[編輯]
right 右對齊(在左側新增填充字元):見 std::right[編輯]
internal 內部對齊(在內部指定點新增填充字元):見 std::internal[編輯]
adjustfield left | right | internal。用於掩碼操作[編輯]
scientific 使用科學記數法生成浮點型別,如果與fixed結合,則使用十六進位制記數法:見 std::scientific[編輯]
fixed 使用固定記數法生成浮點型別,如果與scientific結合,則使用十六進位制記數法:見 std::fixed[編輯]
floatfield scientific | fixed。用於掩碼操作[編輯]
boolalpha 以字母數字格式插入和提取bool型別:見 std::boolalpha[編輯]
showbase 為整數輸出生成指示數字基數的錢綴,在貨幣 I/O 中要求貨幣指示符:見 std::showbase[編輯]
showpoint 為浮點數輸出無條件生成小數點字元:見 std::showpoint[編輯]
showpos 為非負數字輸出生成+字元:見 std::showpos[編輯]
skipws 在某些輸入操作前跳過前導空格:見 std::skipws[編輯]
unitbuf 每次輸出操作後重新整理輸出:見 std::unitbuf[編輯]
uppercase 在某些輸出操作中用大寫字母替換某些小寫字母:見 std::uppercase[編輯]

(型別定義) [編輯]
流狀態型別

還定義了以下常量

常量 解釋[編輯]
goodbit 無錯誤[編輯]
badbit 不可恢復的流錯誤[編輯]
failbit 輸入/輸出操作失敗(格式化或提取錯誤)[編輯]
eofbit 關聯的輸入序列已到達檔案末尾[編輯]

(型別定義) [編輯]
定位方向型別

還定義了以下常量

常量 解釋[編輯]
beg 流的起始位置[編輯]
end 流的結束位置[編輯]
cur 流位置指示器的當前位置[編輯]

(型別定義) [編輯]
指定事件型別
(列舉) [編輯]
回撥函式型別
(型別定義) [編輯]