我需要声明多少次 std::ios::sync_with_stdio(假);在程序中

How many times would I need to declare std::ios::sync_with_stdio(false); in a program

本文关键字:程序 stdio with std 多少次 声明 ios sync      更新时间:2023-10-16

所以,我正在研究一些使我的代码运行更快的方法,我发现printfcout更快。但是,我看到了std::ios::sync_with_stdio(false);通过不同步使 cout 更快。

我现在的问题是:您是否需要在 main 中声明它并且它适用于我的整个程序,或者我需要使用 cout 将其放置在每个函数中,还是我需要将其放置在每个cout之前?

执行任何 I/O 操作之前,您只需要将其放置一次,最好放在 main 中,因为:

如果在标准流上发生 I/O 后调用此函数,则行为由实现定义