c++ - 将 iostream 与 stdio 同步

标签 c++ c stl io legacy-code

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

相关文章:

c++ - 在/usr/local/lib 下找不到库

c++ - 将 Opengl 模型加载到容器中并依次调用它们

c++ - 成对函数评估算法(C++、STL)

ios - 快速将 NSString 转换为 Unsigned Short

c - 谜题: "[] is symmetric"?

c - #if 为预处理器指令定义字符串比较

c++ - map 中的 map Map.Clear() 错误

c++ - 在抛出 std::exception 实例后调用终止

c++ - 固定宽度整数类型的整数文字

C++获取字符串数组的大小