C++ std::ios::sync_with_stdio

一 作用

设置iostream与stdio流的同步(开、关)

二 函数声明

bool sync_with_stdio (bool sync = true);

三 iosream与stdio流的对应关系

C streamiostream
stdincin
wcin
stdoutcout
wcout
stderrcerr
wcerr
clog
wclog

四 说明

Toggles on or off synchronization of all the iostream standard streams with their corresponding standard C streams if it is called before the program performs its first input or output operation.

If called once an input or output operation has occurred, its effects are implementation-defined.

By default, iostream objects and cstdio streams are synchronized (as if this function was called with true as argument).

翻译:如果在程序执行第一次输入或输出前调用,则开或关所有iostream标准流与它们相应的标准C流的同步。如果调用时,已经发生了输入或输出操作,影响将由实现定义。默认情况下,iostream对象和cstdio流是同步的,等效于用true作为参数调用。

c++98

If the streams are synchronized, a program can mix iostream operations with stdio operations, and their observable effects are guaranteed to follow the same order as used in the program.

翻译: 如果流是同步的, 程序可以混合使用iostream和stdio,并且保证他们的观察结果与在程序中使用的顺序相同。

c++11

If the streams are synchronized, a program can mix iostream operations with stdio operations, and their observable effects are guaranteed to follow the same order as used in the thread.

Concurrently accessing synchronized streams (i.e., streams for which this function returns true) never introduces data races: characters are read/written individually, although with no further guarantees on its order between threads. This may result in interleaved characters between threads unless proper synchronization of entire operations is enforced by the program.

翻译: 如果流是同步的, 程序可以混合使用iostream和stdio,并且保证他们的观察结果与在线程中使用的顺序相同。

并发访问同步的流(例如,这个函数返回true的流)永远不会引入数据竞争,字符都是单独读或写的,尽管不能进一步保证线程之间的顺序。这可能导致线程间的字符交错,除非程序强制对整个操作进行了正确同步。

With stdio synchronization turned off, iostream standard stream objects may operate independently of the standard C streams (although they are not required to), and mixing operations may result in unexpectedly interleaved characters.

翻译: 在关闭stdio同步之后,iostream标准流对象可以独立于标准C流进行操作(尽管没有要求这样做),但混合操作可能会导致意外的交错字符。

五 参考

原文: std::ios_base::sync_with_stdio

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值