About Printf-Scanf and Cin-Cout

Can anyone please tell me exactly why printf-scanf works faster than cin-cout?

By default the i/o functions cin and cout are meant to synchronise with the library #include<stdio.h> . This makes them slow. You can change this by adding the following line below the int main () line of your function

std::ios_base::sync_with_stdio(false);

Note that after using this line you cannot use any instances of scanf and printf in your program. Else it’ll give you a runtime error SIGSEGV. Also this makes cin and cout a tad bit faster than scanf and printf. You can check that on the problem INTEST.

1 Like

This link will help you understand better about that.

1 Like

check out this answer on quora: http://www.quora.com/Is-cin-cout-slower-than-scanf-printf

It wil not increase speed of cout though…

http://codeforces.com/blog/entry/6251