My understanding is that the ios::sync line is needed to synchronize the outputs when we use both cout of C++ and print() of C but I have only used C++ then why should I use that line?
My understanding is that the ios::sync line is needed to synchronize the outputs when we use both cout of C++ and print() of C
No, it's the opposite.
By default, the C++ streams have some complicated and relatively time-expensive logic to make sure that if you mix printf-style and std::cout-style streams everything will still be read and printed in the correct order.
However, if you're sure your program only uses cin and cout you can turn off this synchronization with ios::sync_with_stdio(false) and make input considerably faster.
Downvotes can teach as well.When I opened my account I also shitposted and I got a lot of downvotes.I got very angry that day but now I understand why it was downvoted.
add these 2 magic lines:
ios::sync_with_stdio(false); cin.tie(0);
Okay, sorry I had never heard of these functions before.
I tried to read about it here:link
My understanding is that the ios::sync line is needed to synchronize the outputs when we use both cout of C++ and print() of C but I have only used C++ then why should I use that line?
No, it's the opposite.
By default, the C++ streams have some complicated and relatively time-expensive logic to make sure that if you mix
printf
-style andstd::cout
-style streams everything will still be read and printed in the correct order.However, if you're sure your program only uses
cin
andcout
you can turn off this synchronization withios::sync_with_stdio(false)
and make input considerably faster.You said "identical" it's not.
ios::sync_with_stdio(false); cin.tie(0);
Also you need to be careful with "endl" too.
He is new in cf. why some people are downvoting his post? I think we should appreciate him at the beginning and help him to find out his mistake.
Downvotes can teach as well.When I opened my account I also shitposted and I got a lot of downvotes.I got very angry that day but now I understand why it was downvoted.
the thing is, he isn't trash-posting...
...
1.)ios::sync_with_stdio(false); cin.tie(0);
use this for fast input output2.)Avoid using "endl" instead using "\n";
3.) never underestimate a newbie
or
Lmao, agree with the first 2
Just was curious about the last line. Why should we avoid endl?
if you are using endl more than 1e4 time, then you should use "\n" instead , since endl is slower, as it also flush the output.
Never underestimate a specialist
Unless you're Umnik
Agree with the third
if input of a problem contains number <= 10^18, u should use ios::sync_with_stdio(false); cin.tie(0);. It will be much faster
Why he got downvotes, I think there's nothing wrong.