std::basic_filebuf
來自 cppreference.com
定義於標頭檔案 <fstream> |
||
template< class CharT, |
||
std::basic_filebuf
是 std::basic_streambuf 的一個特化,其關聯字元序列是一個檔案。輸入序列和輸出序列都與同一個檔案關聯,並且為這兩個操作維護一個共享的檔案位置。使用 std::basic_filebuf
讀取和寫入序列的限制與 std::FILE 相同。
函式 underflow() 和 overflow() / sync() 在檔案與緩衝區的獲取區和放置區之間執行實際的 I/O。當 CharT
不是 char 時,大多數實現將多位元組字元儲存在檔案中,並使用 std::codecvt facet 執行寬字元/多位元組字元轉換。
提供了用於常見字元型別的幾個 typedef
定義於標頭檔案
<fstream> | |
型別 | 定義 |
std::filebuf
|
std::basic_filebuf<char> |
std::wfilebuf
|
std::basic_filebuf<wchar_t> |
目錄 |
[編輯] 成員型別
型別 | 定義 |
char_type
|
CharT |
traits_type
|
Traits ;如果 Traits::char_type 不是 CharT ,則程式格式錯誤。 |
int_type
|
Traits::int_type |
pos_type
|
Traits::pos_type ,要求為 std::fpos<Traits::state_type> |
off_type
|
Traits::off_type |
native_handle_type (C++26) |
實現定義型別,它是TriviallyCopyable且semiregular 的 |
[編輯] 成員函式
公開成員函式 | |
構造一個 basic_filebuf 物件(public member function) | |
(C++11) |
賦值一個 basic_filebuf 物件(public member function) |
(C++11) |
交換兩個 basic_filebuf 物件(public member function) |
(C++26) |
返回底層實現定義的控制代碼 (public member function) |
[virtual] |
銷燬一個 basic_filebuf 物件,如果檔案已開啟則關閉它(virtual public member function) |
檢查關聯檔案是否開啟 (public member function) | |
開啟一個檔案並將其配置為關聯字元序列 (public member function) | |
重新整理輸出緩衝區並關閉關聯檔案 (public member function) | |
受保護的成員函式 | |
[virtual] |
可選地提供可從檔案中輸入的字元數量 (virtual protected member function) |
[virtual] |
從關聯檔案讀取 (virtual protected member function) |
[virtual] |
從關聯檔案讀取並推進獲取區中的下一指標 (virtual protected member function) |
[virtual] |
回退輸入序列以回推字元,不影響關聯檔案 (virtual protected member function) |
[virtual] |
從放置區向關聯檔案寫入字元 (virtual protected member function) |
[virtual] |
提供使用者提供的緩衝區或將此檔案緩衝區設為無緩衝 (virtual protected member function) |
[virtual] |
使用相對地址重新定位檔案位置 (virtual protected member function) |
[virtual] |
使用絕對地址重新定位檔案位置 (virtual protected member function) |
[virtual] |
從放置區向關聯檔案寫入字元 (virtual protected member function) |
[virtual] |
更改關聯的區域設定 (virtual protected member function) |
[編輯] 非成員函式
特化 std::swap 演算法 (function template) |
繼承自 std::basic_streambuf
成員型別
成員型別 | 定義 |
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 |
成員函式
[virtual] |
銷燬 basic_streambuf 物件(virtual public member function of std::basic_streambuf<CharT,Traits> ) |
區域設定 | |
更改關聯的區域設定並呼叫 imbue() (public member function of std::basic_streambuf<CharT,Traits> ) | |
獲取關聯區域設定的副本 (public member function of std::basic_streambuf<CharT,Traits> ) | |
定位 | |
呼叫 setbuf() (public member function of std::basic_streambuf<CharT,Traits> ) | |
呼叫 seekoff() (public member function of std::basic_streambuf<CharT,Traits> ) | |
呼叫 seekpos() (public member function of std::basic_streambuf<CharT,Traits> ) | |
呼叫 sync() (public member function of std::basic_streambuf<CharT,Traits> ) | |
獲取區 | |
獲取獲取區中立即可用的字元數 (public member function of std::basic_streambuf<CharT,Traits> ) | |
推進輸入序列,然後讀取一個字元而不再次推進 (public member function of std::basic_streambuf<CharT,Traits> ) | |
(C++17 中移除) |
從輸入序列中讀取一個字元並推進序列 (public member function of std::basic_streambuf<CharT,Traits> ) |
從輸入序列中讀取一個字元而不推進序列 (public member function of std::basic_streambuf<CharT,Traits> ) | |
呼叫 xsgetn() (public member function of std::basic_streambuf<CharT,Traits> ) | |
放置區 | |
將一個字元寫入放置區並推進下一個指標 (public member function of std::basic_streambuf<CharT,Traits> ) | |
呼叫 xsputn() (public member function of std::basic_streambuf<CharT,Traits> ) | |
回放 | |
將一個字元放回輸入序列 (public member function of std::basic_streambuf<CharT,Traits> ) | |
將輸入序列中的下一個指標後退一個位置 (public member function of std::basic_streambuf<CharT,Traits> ) |
受保護的成員函式
構造 basic_streambuf 物件(protected member function) | |
(C++11) |
替換 basic_streambuf 物件(protected member function) |
(C++11) |
交換兩個 basic_streambuf 物件(protected member function) |
區域設定 | |
[virtual] |
響應關聯區域設定的更改 (virtual protected member function of std::basic_streambuf<CharT,Traits> ) |
定位 | |
[virtual] |
如果允許,用使用者定義的陣列替換緩衝區 (virtual protected member function of std::basic_streambuf<CharT,Traits> ) |
[virtual] |
使用相對定址重新定位輸入序列、輸出序列或兩者的下一個指標 (virtual protected member function of std::basic_streambuf<CharT,Traits> ) |
[virtual] |
使用絕對定址重新定位輸入序列、輸出序列或兩者的下一個指標 (virtual protected member function of std::basic_streambuf<CharT,Traits> ) |
[virtual] |
將緩衝區與關聯的字元序列同步 (virtual protected member function of std::basic_streambuf<CharT,Traits> ) |
獲取區 | |
[virtual] |
如果已知,獲取關聯輸入序列中可用於輸入的字元數 (virtual protected member function of std::basic_streambuf<CharT,Traits> ) |
[virtual] |
從關聯輸入序列中讀取字元到獲取區 (virtual protected member function of std::basic_streambuf<CharT,Traits> ) |
[virtual] |
從關聯輸入序列中讀取字元到獲取區並推進下一個指標 (virtual protected member function of std::basic_streambuf<CharT,Traits> ) |
[virtual] |
從輸入序列中讀取多個字元 (virtual protected member function of std::basic_streambuf<CharT,Traits> ) |
返回獲取區起始、當前字元和結尾的指標 (protected member function) | |
推進輸入序列中的下一個指標 (protected member function) | |
重新定位輸入序列的起始、下一個和結束指標 (protected member function) | |
放置區 | |
[virtual] |
向輸出序列寫入多個字元 (virtual protected member function of std::basic_streambuf<CharT,Traits> ) |
[virtual] |
從放置區向關聯輸出序列寫入字元 (virtual protected member function of std::basic_streambuf<CharT,Traits> ) |
返回放置區起始、當前字元和結尾的指標 (protected member function) | |
推進輸出序列的下一個指標 (protected member function) | |
重新定位輸出序列的起始、下一個和結束指標 (protected member function) | |
回放 | |
[virtual] |
將一個字元放回輸入序列,可能會修改輸入序列 (virtual protected member function of std::basic_streambuf<CharT,Traits> ) |
[編輯] 註釋
特性測試宏 | 值 | 標準 | 特性 |
---|---|---|---|
__cpp_lib_fstream_native_handle |
202306L |
(C++26) | 原生控制代碼支援 |
[編輯] 參閱
物件型別,能夠儲存控制 C I/O 流所需的所有資訊 (typedef) |