“cpp/io/ostrstream”的版本间的差异

来自cppreference.com
< cpp‎ | io
(P2867R1: REMOVED)
 
第1行: 第1行:
 
{{cpp/title|ostrstream}}
 
{{cpp/title|ostrstream}}
 
{{cpp/io/ostrstream/navbar}}
 
{{cpp/io/ostrstream/navbar}}
{{dcl begin}}
+
{{headerstrstream|deprecated=c++98|=c++26|1=
{{dcl header|strstream}}
+
{{dcl|deprecated=c++98|until=c++26|removed=yes|1=
+
 
class ostrstream : public std::ostream
 
class ostrstream : public std::ostream
 
}}
 
}}
{{dcl end}}
 
  
 
 类 {{tt|ostrstream}} 实现基于数组的流上的输出操作。它实际上将原生数组输入/输出设备实现({{lc|std::strstreambuf}})包装到 {{lc|std::basic_ostream}} 的高层接口中。
 
 类 {{tt|ostrstream}} 实现基于数组的流上的输出操作。它实际上将原生数组输入/输出设备实现({{lc|std::strstreambuf}})包装到 {{lc|std::basic_ostream}} 的高层接口中。
第17行: 第14行:
 
 在任何将结果用作 C 字符串的对 {{lc|str()}} 调用前,缓冲区必须是空终止的,典型地用 {{lc|std::ends}}。
 
 在任何将结果用作 C 字符串的对 {{lc|str()}} 调用前,缓冲区必须是空终止的,典型地用 {{lc|std::ends}}。
  
{{tt|ostrstream}} 从 C++98 起被弃用,推荐用 {{lc|std::ostringstream}} 和 [https://www.boost.org/doc/libs/release/libs/iostreams/doc/classes/array.html#array_sink boost::iostreams::array_sink] 替代。
+
{{tt|ostrstream}} 从 C++98 起被弃用 ,推荐用 {{lc|std::ostringstream}} 和 [https://www.boost.org/doc/libs/release/libs/iostreams/doc/classes/array.html#array_sink boost::iostreams::array_sink] 替代。
  
 
===成员函数===
 
===成员函数===

2024年4月6日 (六) 21:19的最后版本

在标头 <strstream> 定义
class ostrstream : public std::ostream
(C++98 弃用)
(C++26 移除)

ostrstream 实现基于数组的流上的输出操作。它实际上将原生数组输入/输出设备实现(std::strstreambuf)包装到 std::basic_ostream 的高层接口中。

ostrstream 的典型实现仅保有一个非派生的数据成员:std::strstreambuf 类型对象。

目录

[编辑] 注解

在任何对 str() 的调用后,要求调用 freeze(false) 以允许析构函数在必要时解分配缓冲区。

在任何将结果用作 C 字符串的对 str() 调用前,缓冲区必须是空终止的,典型地用 std::ends

ostrstream 从 C++98 起被弃用并从 C++26 起被移除,推荐用 std::ostringstreamstd::ospanstream(C++23 起)boost::iostreams::array_sink 替代。

[编辑] 成员函数

构造 ostrstream 对象,部分情况下会分配缓冲区
(公开成员函数) [编辑]
析构 ostrstream 对象,部分情况下会解分配缓冲区
(虚公开成员函数) [编辑]
获得指向关联 strstreambuf 的指针
(公开成员函数) [编辑]
访问输出缓冲区
(公开成员函数) [编辑]
禁用/启用自动解分配
(公开成员函数) [编辑]
获得写入的字符数
(公开成员函数) [编辑]

继承自 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> 的公开成员函数) [编辑]
检查是否没有发生错误(!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> 的公开成员函数) [编辑]

继承自 std::ios_base

成员函数

格式化
管理格式标志
(std::ios_base 的公开成员函数) [编辑]
设置特定格式标志
(std::ios_base 的公开成员函数) [编辑]
清除特定格式的标志
(std::ios_base 的公开成员函数) [编辑]
管理浮点数操作的精度
(std::ios_base 的公开成员函数) [编辑]
管理字段宽度
(std::ios_base 的公开成员函数) [编辑]
本地环境
设置本地环境
(std::ios_base 的公开成员函数) [编辑]
返回当前本地环境
(std::ios_base 的公开成员函数) [编辑]
内部可扩展数组
[静态]
返回能安全用作 pword()iword() 的索引的程序范围内独有的整数
(std::ios_base 的公开静态成员函数) [编辑]
若必要则调整私有存储的大小,并访问位于给定索引的 long 元素
(std::ios_base 的公开成员函数) [编辑]
若需要则调整私有存储的大小,并访问位于给定索引的 void* 元素
(std::ios_base 的公开成员函数) [编辑]
杂项
注册事件回调函数
(std::ios_base 的公开成员函数) [编辑]
设置 C++ 和 C 的输入/输出库是否可以互操作
(std::ios_base 的公开静态成员函数) [编辑]
成员类