我正在尝试将 iostream 添加到遗留代码中,因此想要同步这两个库。 根据这个article ,我应该使用 std::ios_base::sync_with_stdio。
现在,我想知道它在实践中是如何使用的(请举例),以及我应该注意的副作用。
谢谢
最佳答案
默认情况下,流是同步的,保证按标准工作,您无需执行任何操作。 sync_with_stdio
仅在您需要时禁用同步。
来自您提到的文章:
For the predefined streams, it's safe to mix stdio and iostreams. For example, you can safely use stdin and cin in the same program; the C++ Standard guarantees that it will work the way you would naively expect it to.
唯一的缺点是可能会影响性能(我想这就是可以禁用它的原因)。
关于c++ - 将 iostream 与 stdio 同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1595355/