命名空间
变体
操作

std::basic_istringstream

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

    class CharT,
    class Traits = std::char_traits<CharT>,
    class Allocator = std::allocator<CharT>

> class basic_istringstream : public basic_istream<CharT, Traits>;

类模板 std::basic_istringstream 对基于字符串的流实现输入操作。它有效地存储 std::basic_string 的实例并对其执行输入操作。

在底层,该类实际上将 std::basic_stringbuf 的原始字符串设备实现封装到 std::basic_istream 的高级接口中。提供了 std::basic_stringbuf 唯一成员的完整接口。

cpp/io/ios basecpp/io/basic ioscpp/io/basic istreamstd-basic istringstream-inheritance.svg

继承图

提供了用于常见字符类型的几个 typedef

定义于头文件 <sstream>
类型 定义
std::istringstream std::basic_istringstream<char>
std::wistringstream std::basic_istringstream<wchar_t>

目录

[编辑] 成员类型

成员类型 定义
char_type CharT[编辑]
traits_type Traits;若 Traits::char_typeCharT 则程序非良构。[编辑]
int_type Traits::int_type[编辑]
pos_type Traits::pos_type[编辑]
off_type Traits::off_type[编辑]
allocator_type Allocator[编辑]

[编辑] 仅供说明的成员

名称 定义
sb 用作底层缓冲区的 std::basic_stringbuf<CharT, Traits, Allocator>
(仅用于阐释的成员对象*)

[编辑] 成员函数

构造字符串流
(public member function) [编辑]
(C++11)
移动字符串流
(public member function) [编辑]
(C++11)
交换两个字符串流
(public member function) [编辑]
返回底层原始字符串设备对象
(public member function) [编辑]
字符串操作
获取或设置底层字符串设备对象的内容
(public member function) [编辑]
(C++20)
获取底层字符串设备对象内容的视图
(public member function) [编辑]

[编辑] 非成员函数

特化 std::swap 算法
(function template) [编辑]

继承自 std::basic_istream

成员函数

格式化输入
提取格式化数据
(public member function of std::basic_istream<CharT,Traits>) [编辑]
非格式化输入
提取字符
(public member function of std::basic_istream<CharT,Traits>) [编辑]
读取下一个字符而不提取它
(public member function of std::basic_istream<CharT,Traits>) [编辑]
取消提取字符
(public member function of std::basic_istream<CharT,Traits>) [编辑]
将字符放入输入流
(public member function of std::basic_istream<CharT,Traits>) [编辑]
提取字符直到找到给定字符
(public member function of std::basic_istream<CharT,Traits>) [编辑]
提取并丢弃字符直到找到给定字符
(public member function of std::basic_istream<CharT,Traits>) [编辑]
提取字符块
(public member function of std::basic_istream<CharT,Traits>) [编辑]
提取已有的字符块
(public member function of std::basic_istream<CharT,Traits>) [编辑]
返回上次未格式化输入操作提取的字符数
(public member function of std::basic_istream<CharT,Traits>) [编辑]
定位
返回输入位置指示符
(public member function of std::basic_istream<CharT,Traits>) [编辑]
设置输入位置指示符
(public member function of std::basic_istream<CharT,Traits>) [编辑]
杂项
与底层存储设备同步
(public member function of std::basic_istream<CharT,Traits>) [编辑]

成员类

为输入操作准备流实现基本逻辑
(public member class of std::basic_istream<CharT,Traits>) [编辑]

继承自 std::basic_ios

成员类型

成员类型 定义
char_type CharT
traits_type 特性
int_type Traits::int_type
pos_type Traits::pos_type
off_type Traits::off_type

成员函数

状态函数
检查是否没有发生错误,即 I/O 操作可用
(public member function of std::basic_ios<CharT,Traits>) [编辑]
检查是否已到达文件末尾
(public member function of std::basic_ios<CharT,Traits>) [编辑]
检查是否发生错误
(public member function of std::basic_ios<CharT,Traits>) [编辑]
检查是否发生不可恢复的错误
(public member function of std::basic_ios<CharT,Traits>) [编辑]
检查是否发生错误(fail() 的同义词)
(public member function of std::basic_ios<CharT,Traits>) [编辑]
检查是否没有发生错误(!fail() 的同义词)
(public member function of std::basic_ios<CharT,Traits>) [编辑]
返回状态标志
(public member function of std::basic_ios<CharT,Traits>) [编辑]
设置状态标志
(public member function of std::basic_ios<CharT,Traits>) [编辑]
修改状态标志
(public member function of std::basic_ios<CharT,Traits>) [编辑]
格式化
复制格式化信息
(public member function of std::basic_ios<CharT,Traits>) [编辑]
管理填充字符
(public member function of std::basic_ios<CharT,Traits>) [编辑]
杂项
管理异常掩码
(public member function of std::basic_ios<CharT,Traits>) [编辑]
设置区域设置
(public member function of std::basic_ios<CharT,Traits>) [编辑]
管理关联的流缓冲区
(public member function of std::basic_ios<CharT,Traits>) [编辑]
管理绑定的流
(public member function of std::basic_ios<CharT,Traits>) [编辑]
窄化字符
(public member function of std::basic_ios<CharT,Traits>) [编辑]
宽化字符
(public member function of std::basic_ios<CharT,Traits>) [编辑]

继承自 std::ios_base

成员函数

格式化
管理格式标志
(public member function of std::ios_base) [编辑]
设置特定格式标志
(public member function of std::ios_base) [编辑]
清除特定格式标志
(public member function of std::ios_base) [编辑]
管理浮点运算的十进制精度
(public member function of std::ios_base) [编辑]
管理字段宽度
(public member function of std::ios_base) [编辑]
区域设置
设置区域设置
(public member function of std::ios_base) [编辑]
返回当前区域设置
(public member function of std::ios_base) [编辑]
内部可扩展数组
[静态]
返回一个程序范围内的唯一整数,可安全用作 pword()iword() 的索引
(public static member function of std::ios_base) [编辑]
如有必要,调整私有存储的大小,并访问给定索引处的 long 元素
(public member function of std::ios_base) [编辑]
如有必要,调整私有存储的大小,并访问给定索引处的 void* 元素
(public member function of std::ios_base) [编辑]
杂项
注册事件回调函数
(public member function of std::ios_base) [编辑]
设置 C++ 和 C I/O 库是否可互操作
(public static member function of std::ios_base) [编辑]
成员类
流异常
(public member class of std::ios_base) [编辑]
初始化标准流对象
(public member class of std::ios_base) [编辑]

成员类型和常量

类型 解释
流打开模式类型

还定义了以下常量

常数 解释[编辑]
app 在每次写入前定位到流的末尾[编辑]
二进制 二进制模式打开[编辑]
in 为读取打开[编辑]
out 为写入打开[编辑]
trunc 打开时丢弃流的内容[编辑]
ate 打开后立即定位到流的末尾[编辑]
noreplace (C++23) 以独占模式打开[编辑]

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

还定义了以下常量

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

(typedef) [编辑]
流状态类型

还定义了以下常量

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

(typedef) [编辑]
定位方向类型

还定义了以下常量

常数 解释[编辑]
beg 流的开始[编辑]
end 流的结束[编辑]
cur 流位置指示器的当前位置[编辑]

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