cout or printf which of the two has a faster execution speed C++?

后端 未结 15 2856
旧时难觅i
旧时难觅i 2020-11-27 07:04

I have been coding in C++ for a long time. I always wondered which has a faster execution speed printf or cout?

Situation: I am designing a

15条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 07:23

    On Windows at least, writing to the console is a huge bottleneck, so a "noisy" console mode program will be far slower than a silent one. So on that platform, slight differences in the library functions used to address the console will probably make no significant difference in practice.

    On other platforms it may be different. Also it depends just how much console output you are doing, relative to other useful work.

    Finally, it depends on your platform's implementation of the C and C++ I/O libraries.

    So there is no general answer to this question.

提交回复
热议问题