std::basic_osyncstream
在标头
<syncstream> 定义 |
||
template<
class CharT, |
(C++20 起) | |
类模板 std::basic_osyncstream
是 std::basic_syncbuf 的便利包装。它提供机制以对写入同一流的各线程进行同步。
它能用作具名变量:
还有临时量:
std::osyncstream(std::cout) << "Hello, " << "World!" << '\n';
它提供保证:所有对最终目标缓冲区(上例中是 std::cout)作出的输出将免除数据竞争,而且将不以任何方式穿插或截断,只要每次对该最终目标缓冲区的写入都通过 std::basic_osyncstream
(可以不同的)实例进行。
std::basic_osyncstream
的典型实现仅保有一个数据成员:被包装的 std::basic_syncbuf。
继承图
提供了几个针对常用字符类型的 typedef:
在标头
<syncstream> 定义 |
|
类型 | 定义 |
std::osyncstream |
std::basic_osyncstream<char> |
std::wosyncstream |
std::basic_osyncstream<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 |
allocator_type |
Allocator |
streambuf_type |
std::basic_streambuf<CharT, Traits> |
syncbuf_type |
std::basic_syncbuf<CharT, Traits, Allocator> |
成员函数
构造 basic_osyncstream 对象(公开成员函数) |
|
赋值 basic_osyncstream 对象(公开成员函数) |
|
销毁 basic_osyncstream 并发出它的内部缓冲区(公开成员函数) |
|
获得指向底层 basic_syncbuf 的指针(公开成员函数) |
|
获得指向最终目标流缓冲的指针 (公开成员函数) |
|
调用底层 basic_syncbuf 上的 emit() 以传输它的内部数据到最终目标(公开成员函数) |
继承自 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 的公开静态成员函数) |
成员类 |
|
流异常 ( std::ios_base 的公开成员类) |
|
初始化标准流对象 ( std::ios_base 的公开成员类) |
成员类型和常量 |
|||||||||||||||||||||||||||||||||||||||
类型 | 解释 | ||||||||||||||||||||||||||||||||||||||
流打开模式类型 同时定义下列常量:
(typedef) |
|||||||||||||||||||||||||||||||||||||||
格式化标志类型
亦定义下列常量:
(typedef) |
|||||||||||||||||||||||||||||||||||||||
流状态类型
亦定义下列常量:
(typedef) |
|||||||||||||||||||||||||||||||||||||||
寻位方向类型
亦定义下列常量:
(typedef) |
|||||||||||||||||||||||||||||||||||||||
指定事件类型 (枚举) |
|||||||||||||||||||||||||||||||||||||||
回调函数类型 (typedef) |
注解
功能特性测试宏 | 值 | 标准 | 功能特性 |
---|---|---|---|
__cpp_lib_syncbuf |
201803L | (C++20) | 带同步的缓冲 ostream(std::osyncstream ,std::syncbuf)和操纵符 |