◐ Shell
clean mode source ↗

std::basic_iostream - cppreference.com

来自cppreference.com

template< 
    class CharT, 
    class Traits = std::char_traits<CharT>
> class basic_iostream : 
      public basic_istream<CharT, Traits>,
      public basic_ostream<CharT, Traits>

类模板 basic_iostream 提供在流上进行高层输入/输出支持。受支持操作包含按顺序的读或写及格式化。此功能在 std::basic_streambuf 类提供的接口上实现。通过 std::basic_ios 类访问缓冲区。

cpp/io/ios basecpp/io/basic ioscpp/io/basic istreamcpp/io/basic ostream

继承图

提供了几个针对常用字符类型的 typedef:

类型 定义
std::iostream std::basic_iostream<char>
std::wiostream std::basic_iostream<wchar_t>

成员类型

成员类型 定义
char_type CharT[编辑]
traits_type TraitsTraits::char_type 不是 CharT 时程序非良构。[编辑]
int_type Traits::int_type[编辑]
pos_type Traits::pos_type[编辑]
off_type Traits::off_type[编辑]

成员函数

受保护成员函数

继承自 std::basic_istream

成员函数

有格式输入
提取带格式数据
(std::basic_istream<CharT,Traits> 的公开成员函数) [编辑]
无格式输入
提取字符
(std::basic_istream<CharT,Traits> 的公开成员函数) [编辑]
读取下一个字符,但不会提取它
(std::basic_istream<CharT,Traits> 的公开成员函数) [编辑]
撤销上一个字符的提取
(std::basic_istream<CharT,Traits> 的公开成员函数) [编辑]
往输入流中放置一个字符
(std::basic_istream<CharT,Traits> 的公开成员函数) [编辑]
持续提取字符,直到找到给定字符
(std::basic_istream<CharT,Traits> 的公开成员函数) [编辑]
持续提取并丢弃字符,直到找到给定字符
(std::basic_istream<CharT,Traits> 的公开成员函数) [编辑]
按区块提取字符
(std::basic_istream<CharT,Traits> 的公开成员函数) [编辑]
提取已经可用的字符区块
(std::basic_istream<CharT,Traits> 的公开成员函数) [编辑]
返回上次无格式输入操作提取的字符数量
(std::basic_istream<CharT,Traits> 的公开成员函数) [编辑]
寻位
返回输入位置指示器
(std::basic_istream<CharT,Traits> 的公开成员函数) [编辑]
设置输入位置指示器
(std::basic_istream<CharT,Traits> 的公开成员函数) [编辑]
杂项
与底层存储设备同步
(std::basic_istream<CharT,Traits> 的公开成员函数) [编辑]

成员类

实现为输出操作准备流的基本逻辑
(std::basic_istream<CharT,Traits> 的公开成员类) [编辑]

继承自 std::basic_ostream

成员函数

有格式输出
插入带格式数据
(std::basic_ostream<CharT,Traits> 的公开成员函数) [编辑]
无格式输出
插入字符
(std::basic_ostream<CharT,Traits> 的公开成员函数) [编辑]
按区块插入字符
(std::basic_ostream<CharT,Traits> 的公开成员函数) [编辑]
寻位
返回输出位置指示器
(std::basic_ostream<CharT,Traits> 的公开成员函数) [编辑]
设置输出位置指示器
(std::basic_ostream<CharT,Traits> 的公开成员函数) [编辑]
杂项
与底层存储设备同步
(std::basic_ostream<CharT,Traits> 的公开成员函数) [编辑]

成员类

为输出操作实现流准备的基本逻辑
(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

成员函数

状态函数
检查是否没有发生错误,即是否可执行输入/输出操作
(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> 的公开成员函数) [编辑]
检查是否没有发生错误(!std::basic_ios::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> 的公开成员函数) [编辑]

缺陷报告

下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。

缺陷报告 应用于 出版时的行为 正确行为
LWG 271 C++98 未定义成员类型 char_typetraits_typeint_typepos_typeoff_type
std::basic_istreamstd::basic_ostream 都定义了这些类型,会导致有歧义)
定义这些类型

参阅

输入/输出操纵符