gpt4 book ai didi

c++ - 我需要声明多少次 std::ios::sync_with_stdio(false);在一个程序中

转载 作者:太空狗 更新时间:2023-10-29 21:11:51 25 4
gpt4 key购买 nike

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

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

最佳答案

您只需将它放置一次,最好是在 main 中,在执行任何 I/O 操作之前 since :

If this function is called after I/O has occurred on the standard stream, the behavior is implementation-defined

关于c++ - 我需要声明多少次 std::ios::sync_with_stdio(false);在一个程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49270714/

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