7
In competitive programming it is common for several programmers to use scanf()
and printf()
in C++ code instead of using cin
and cout
.
And I’ve even seen problems that result in a Time Limit Exceeded (TLE - Time Limit Exceeded) when used cin
and cout
, but run within time when used scanf()
and printf()
, implementing the same idea in the algorithms.
Then there’s the doubt, scanf()
is always faster than cin
, will depend on the case or cin
is faster?
I fully agree with you. I would even say that the implementation of a good compiler don’t need be overly concerned about equal performance, as the overall objective is not competition. So, maybe there are differences, but they are disregardable for almost all scenarios other than the competition. Even so, my intuition tells me that C++ streams tend to be slower due to OO implementation indirect. Don’t you think? If you have any indication otherwise, I think it would be nice to share it in the answer. :)
– Luiz Vieira
I also thought, until I saw some tests :) I’ll see if I find any. I think it may be that the overhead of Parsing formatting may be the cause, but I’m guessing.
– Maniero
True, it may be.
– Luiz Vieira
Cin good, scanf bad (not in terms of time, but in terms of usability)
– zentrunix
@Joséx. also.
– Maniero