std::basic_filebuf
来自 cppreference.cn
定义于头文件 <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) |