◐ Shell
clean mode source ↗

std::basic_ostringstream - cppreference.com

来自cppreference.com

template<
    class CharT,
    class Traits = std::char_traits<CharT>,
    class Allocator = std::allocator<CharT>
> class basic_ostringstream
    : public basic_ostream<CharT, Traits>;

类模板 std::basic_ostringstream 实现基于字符串的流上的输出操作。它相当于存储一个 std::basic_string 的实例,并在它之上进行输出操作。

该类实际上在低层将一个 std::basic_stringbuf 的原生字符串设备实现包装到 std::basic_ostream 的高层接口中。它提供到独有 std::basic_stringbuf 成员的完整接口。

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

继承图

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

类型 定义
std::ostringstream std::basic_ostringstream<char>
std::wostringstream std::basic_ostringstream<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[编辑]
allocator_type Allocator[编辑]

仅用于阐述的成员

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

成员函数

构造字符串流
(公开成员函数) [编辑]

(C++11)

移动字符串流
(公开成员函数) [编辑]

(C++11)

交换两个字符串流
(公开成员函数) [编辑]
返回底层原生字符串设备对象
(公开成员函数) [编辑]
字符串操作
获取或设置底层字符串设备对象的内容
(公开成员函数) [编辑]

(C++20)

获得底层字符串设备的内容上的视图
(公开成员函数) [编辑]

非成员函数

继承自 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> 的公开成员函数) [编辑]