命名空间
变体
操作

std::basic_spanstream

来自 cppreference.cn
< cpp‎ | io
定义于头文件 <spanstream>
template<

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

    : public basic_iostream<CharT, Traits>
(自 C++23 起)

类模板 std::basic_spanstream 基于固定缓冲区实现流上的输入和输出操作。

在底层,此类本质上将 std::basic_spanbuf 的原始设备实现包装到 std::basic_iostream 的更高级接口中。 提供了到唯一 std::basic_spanbuf 成员的完整接口。

cpp/io/ios basecpp/io/basic ioscpp/io/basic istreamcpp/io/basic ostreamcpp/io/basic iostreamstd-basic spanstream-inheritance.svg

继承关系图

为常用字符类型提供了几个 typedef

定义于头文件 <spanstream>
类型 定义
std::spanstream std::basic_spanstream<char>
std::wspanstream std::basic_spanstream<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[编辑]

[编辑] 数据成员

成员名称 定义
sb (私有) 包装的 std::basic_spanbuf
(仅用于演示的成员对象*)

[编辑] 成员函数

构造 basic_spanstream
(公有成员函数) [编辑]
(析构函数)
[虚函数]
销毁 basic_spanstream
(虚公有成员函数)
移动赋值 basic_spanstream
(公有成员函数) [编辑]
交换两个 basic_spanstream 对象
(公有成员函数) [编辑]
获取包装的原始 span 设备对象的地址
(公有成员函数) [编辑]
底层缓冲区操作
获取或设置包装的 span 设备对象的底层缓冲区
(公有成员函数) [编辑]

[编辑] 非成员函数

特化 std::swap 算法
(函数模板) [编辑]

继承自 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

成员函数

状态函数
检查是否没有错误发生,即 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> 的公有成员函数) [编辑]
rdbuf
管理关联的流缓冲区
管理绑定的流
(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 的公有成员函数) [编辑]
区域设置
imbue
(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 每次写入前查找流的末尾[编辑]
binary 二进制模式下打开[编辑]
in 打开以进行读取[编辑]
out 打开以进行写入[编辑]
trunc 打开时丢弃流的内容[编辑]
ate 打开后立即查找流的末尾[编辑]
noreplace (C++23) 以独占模式打开[edit]

(typedef) [edit]
格式化标志类型

还定义了以下常量

常量 说明[edit]
dec 对整数 I/O 使用十进制基数:参见 std::dec[edit]
oct 对整数 I/O 使用八进制基数:参见 std::oct[edit]
hex 对整数 I/O 使用十六进制基数:参见 std::hex[edit]
basefield dec | oct | hex。 用于掩码操作[edit]
left 左对齐调整(在右侧添加填充字符):参见 std::left[edit]
right 右对齐调整(在左侧添加填充字符):参见 std::right[edit]
internal 内部调整(在内部指定点添加填充字符):参见 std::internal[edit]
adjustfield left | right | internal。 用于掩码操作[edit]
scientific 使用科学计数法生成浮点类型,或与 fixed 结合使用时生成十六进制计数法:参见 std::scientific[edit]
fixed 使用定点计数法生成浮点类型,或与 scientific 结合使用时生成十六进制计数法:参见 std::fixed[edit]
floatfield scientific | fixed。 用于掩码操作[edit]
boolalpha 以字母数字格式插入和提取 bool 类型:参见 std::boolalpha[edit]
showbase 为整数输出生成指示数字基数的前缀,在货币 I/O 中需要货币指示符:参见 std::showbase[edit]
showpoint 无条件地为浮点数输出生成小数点字符:参见 std::showpoint[edit]
showpos 为非负数输出生成 + 字符:参见 std::showpos[edit]
skipws 在某些输入操作之前跳过前导空白符:参见 std::skipws[edit]
unitbuf 在每次输出操作后刷新输出:参见 std::unitbuf[edit]
uppercase 在某些输出操作中,将某些小写字母替换为其大写等效字母:参见 std::uppercase[edit]

(typedef) [edit]
流状态类型

还定义了以下常量

常量 说明[edit]
goodbit 无错误[edit]
badbit 不可恢复的流错误[edit]
failbit 输入/输出操作失败(格式化或提取错误)[edit]
eofbit 关联的输入序列已到达文件末尾[edit]

(typedef) [edit]
查找方向类型

还定义了以下常量

常量 说明[edit]
beg 流的开始[edit]
end 流的结尾[edit]
cur 流位置指示器的当前位置[edit]

(typedef) [edit]
指定事件类型
(enum) [edit]
回调函数类型
(typedef) [edit]

[edit] 注释

特性测试 标准 特性
__cpp_lib_spanstream 202106L (C++23) std::spanbuf, std::spanstream