gpt4 book ai didi

c++ - 将 iostream 与 stdio 同步

转载 作者:太空狗 更新时间:2023-10-29 23:38:18 30 4
gpt4 key购买 nike

我正在尝试将 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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com