+ 2

Which one is better in cpp compiler?

cin and cout OR scanf and printf? Which one is better and why?

9th Jun 2020, 2:20 PM
Ashfaq Reshad
Ashfaq Reshad - avatar
7 Antworten
+ 5
Ashfaq Reshad in competitive programming cin and cout is almost 5 times slower than printf() and scanf() but you can still use cin/cout and achieve the same speed as scanf/printf by including the following two lines in your main() function👇 ios_base::sync_with_stdio(false); cin.tie(NULL); Learn more about it here👇 https://www.geeksforgeeks.org/fast-io-for-competitive-programming/amp/
9th Jun 2020, 3:02 PM
Arsenic
Arsenic - avatar
+ 2
Ninja Coder Arsenic Thank you both <3
9th Jun 2020, 3:05 PM
Ashfaq Reshad
Ashfaq Reshad - avatar
+ 1
You shouldn't use scanf() over cin if you are writing C++ software because that is want cin is for. If you want performance, you probably wouldn't be writing I/O in C++ anyway. The statements cin and cout in general use seem to be slower than scanf and printf in C++, but actually they are FASTER!
9th Jun 2020, 2:48 PM
Kashyap Kumar
Kashyap Kumar - avatar
0
As I know cin and cout is for C++, rest are for C. These are standard.
9th Jun 2020, 2:45 PM
Kashyap Kumar
Kashyap Kumar - avatar
0
Ninja Coder people says that cin & cout is slower than scanf & printf
9th Jun 2020, 2:46 PM
Ashfaq Reshad
Ashfaq Reshad - avatar
0
Ninja Coder in terms of competitive programming which one is better? If cin & cout is slow i may have to go with time limit exceeded problem...
9th Jun 2020, 2:50 PM
Ashfaq Reshad
Ashfaq Reshad - avatar
0
Ashfaq Reshad Sorry, I have no answer for that. You should google it for the best answer
9th Jun 2020, 3:03 PM
Kashyap Kumar
Kashyap Kumar - avatar