【问题标题】:std::ios_base::sync_with_stdio(false), advantages, disadvantages?std::ios_base::sync_with_stdio(false),优点,缺点?
【发布时间】:2022-01-15 01:10:19
【问题描述】:

std::ios_base::sync_with_stdio( false );有什么区别
对比std::cout.sync_with_stdio( false );std::cin.sync_with_stdio( false );

如果我的代码不使用来自 <cstdio> 的任何 C 流并且只使用来自 <iostream> 的 C++ 流,我应该使用哪一个?

我想知道:

  1. 禁用同步有什么好处?
  2. 如果同步设置为 false,会出现什么问题?如果我想禁用同步,应该考虑哪些事项?

【问题讨论】:

  • 一个问题一个问题。

标签: c++ io iostream cstdio


【解决方案1】:

sync_with_stdio 是一个static 函数。

所以

std::cout.sync_with_stdio(false);

事实上

std::cout, std::ios_base::sync_with_stdio(false);

【讨论】:

  • 我不明白最后一行。
  • std::cout 被评估(并丢弃结果)。基本相当于std::ios_base::sync_with_stdio(false);
  • 所以没有区别?我认为std::cout.sync_with_stdio(false); 只禁用了 std::cout 的同步,std::ios_base::sync_with_stdio(false); 禁用了所有八个 C++ 流对象的同步。这不是真的吗?
  • @digito_evo 如果您不理解包含逗号的表达式,那么您可能应该阅读 C++ 中的 built-in comma operator
  • @heap underrun 感谢您的链接。现在我明白了。
猜你喜欢
  • 1970-01-01
  • 2018-01-11
  • 2015-09-18
  • 2022-01-15
  • 2018-08-20
  • 2016-02-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多