定义于头文件 <fstream>
| template<
class CharT, |
类模板 basic_ifstream 实现文件流上的高层输入操作。它将 std::basic_istream 的高层接口赋予基于文件的流缓冲( std::basic_filebuf )。
std::basic_ifstream 的典型实现仅保有一个非导出数据成员: std::basic_filebuf<CharT, Traits> 的实例。

亦对常用字符类型定义二个特化:
| 类型 | 定义 |
ofstream | basic_ofstream<char> |
wofstream | basic_ofstream<wchar_t> |
成员类型
| 成员类型 | 定义 |
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 |
成员函数
|
(构造函数) | 构造文件流 (公开成员函数) |
|
(析构函数) [虚] (隐式声明) | 析构 basic_ofstream 和关联的缓冲区,并关闭文件 (虚公开成员函数) |
|
operator= (C++11) | 移动文件流 (公开成员函数) |
|
swap (C++11) | 交换二个文件流 (公开成员函数) |
|
rdbuf | 返回底层未处理的文件设备对象 (公开成员函数) |
文件操作 | |
|
is_open | 检查流是否有关联文件 (公开成员函数) |
|
open | 打开文件,并将它与流关联 (公开成员函数) |
|
close | 关闭关联文件 (公开成员函数) |
非成员函数
|
std::swap(std::basic_ofstream) (C++11) | 特化 std::swap 算法 (函数模板) |
继承自 std::basic_ostream
成员函数
有格式输出 | |
|
operator<< | 插入带格式数据 ( std::basic_ostream<CharT,Traits> 的公开成员函数) |
无格式输出 | |
|
put | 插入字符 ( std::basic_ostream<CharT,Traits> 的公开成员函数) |
|
write | 插入字符块 ( std::basic_ostream<CharT,Traits> 的公开成员函数) |
寻位 | |
|
tellp | 返回输出位置指示器 ( std::basic_ostream<CharT,Traits> 的公开成员函数) |
|
seekp | 设置输出位置指示器 ( std::basic_ostream<CharT,Traits> 的公开成员函数) |
杂项 | |
|
flush | 与底层存储设备同步 ( std::basic_ostream<CharT,Traits> 的公开成员函数) |
成员类
|
sentry | 为输出操作实现流准备的基本逻辑 ( std::basic_ostream<CharT,Traits> 的公开成员类) |
继承自 std::basic_ios
成员类型
| 成员类型 | 定义 |
char_type | CharT |
traits_type | Traits |
int_type | Traits::int_type |
pos_type | Traits::pos_type |
off_type | Traits::off_type |
成员函数
状态函数 | |
|
good | 检查是否没有发生错误,例如是否可执行I/O操作 ( std::basic_ios<CharT,Traits> 的公开成员函数) |
|
eof | 检查是否到达了文件末尾 ( std::basic_ios<CharT,Traits> 的公开成员函数) |
|
fail | 检查是否发生了可恢复的错误 ( std::basic_ios<CharT,Traits> 的公开成员函数) |
|
bad | 检查是否已发生不可恢复的错误 ( std::basic_ios<CharT,Traits> 的公开成员函数) |
|
operator! | 检查是否有错误发生(fail() 的同义词) ( std::basic_ios<CharT,Traits> 的公开成员函数) |
|
operator void*operator bool (C++11 前)(C++11 起) | 检查是否没有发生错误(!fail()的同义词) ( std::basic_ios<CharT,Traits> 的公开成员函数) |
|
rdstate | 返回状态标志 ( std::basic_ios<CharT,Traits> 的公开成员函数) |
|
setstate | 设置状态标志 ( std::basic_ios<CharT,Traits> 的公开成员函数) |
|
clear | 修改状态标志 ( std::basic_ios<CharT,Traits> 的公开成员函数) |
格式化 | |
|
copyfmt | 复制格式化信息 ( std::basic_ios<CharT,Traits> 的公开成员函数) |
|
fill | 管理填充字符 ( std::basic_ios<CharT,Traits> 的公开成员函数) |
杂项 | |
|
exceptions | 管理异常掩码 ( std::basic_ios<CharT,Traits> 的公开成员函数) |
|
imbue | 设置本地环境 ( std::basic_ios<CharT,Traits> 的公开成员函数) |
|
rdbuf | 管理相关的流缓冲区 ( std::basic_ios<CharT,Traits> 的公开成员函数) |
|
tie | 管理绑定的流 ( std::basic_ios<CharT,Traits> 的公开成员函数) |
|
narrow | 窄化字符 ( std::basic_ios<CharT,Traits> 的公开成员函数) |
|
widen | 拓宽字符 ( std::basic_ios<CharT,Traits> 的公开成员函数) |
继承自 std::ios_base
成员函数
格式化 | |
|
flags | 管理格式标志 ( std::ios_base 的公开成员函数) |
|
setf | 设置特定格式标志 ( std::ios_base 的公开成员函数) |
|
unsetf | 清除特定格式的标志 ( std::ios_base 的公开成员函数) |
|
precision | 管理浮点操作的精度 ( std::ios_base 的公开成员函数) |
|
width | 管理域的宽度 ( std::ios_base 的公开成员函数) |
本地环境 | |
|
imbue | 设置本地环境 ( std::ios_base 的公开成员函数) |
|
getloc | 返回当前本地环境 ( std::ios_base 的公开成员函数) |
内部可扩展数组 | |
|
xalloc [静态] | 返回能安全用作 pword() 和 iword() 下标的程序范围内独有的整数 ( std::ios_base 的公开静态成员函数) |
|
iword | 如果有必要的话,调整私有存储的大小,并且访问位于提供的下标的long元素 ( std::ios_base 的公开成员函数) |
|
pword | 若需要则重置私有存储的大小,并访问位于指定下标的 void* 元素 ( std::ios_base 的公开成员函数) |
杂项 | |
|
register_callback | 注册事件回调函数 ( std::ios_base 的公开成员函数) |
|
sync_with_stdio [静态] | 设置C++和C的IO库是否可以互操作 ( std::ios_base 的公开静态成员函数) |
成员类 | |
|
failure | 流异常 ( std::ios_base 的公开成员类) |
|
Init | 初始化标准流对象 ( std::ios_base 的公开成员类) |
成员类型和常量 | |||||||||||||||||||||||||||||||||||||||
| 类型 | 解释 | ||||||||||||||||||||||||||||||||||||||
|
openmode | 流打开模式类型
亦定义下列常量:
| ||||||||||||||||||||||||||||||||||||||
|
fmtflags | 格式化标志类型
亦定义下列常量:
| ||||||||||||||||||||||||||||||||||||||
|
iostate | 流状态类型
亦定义下列常量:
| ||||||||||||||||||||||||||||||||||||||
|
seekdir | 寻位方向类型
亦定义下列常量:
| ||||||||||||||||||||||||||||||||||||||
|
event | 指定事件类型 (枚举) | ||||||||||||||||||||||||||||||||||||||
|
event_callback | 回调函数类型 (typedef) | ||||||||||||||||||||||||||||||||||||||
本文详细介绍了C++中的基本_ifstream和基本_ofstream类模板,这两个类用于实现文件流的高级输入和输出操作,包括构造、析构、流控制、文件操作和各种成员函数,如open、close、read和write等。
(std::basic_ofstream)(一)&spm=1001.2101.3001.5002&articleId=132008259&d=1&t=3&u=8a58c763ba20469a8cc333d16463c852)
1284

被折叠的 条评论
为什么被折叠?



