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