princebelkovetz's blog

By princebelkovetz, history, 7 days ago, In English,

Hello everyone! Sometimes I have problems on the C++ with TLE because of standart cin and cout. Personally, I prefer to use cin.tie(0) and cout.tie(0) in such situations, but some people prefer scanf and printf. Can you explain, what is the difference, what is better to use and why?

 
 
 
 
  • Vote: I like it
  • +11
  • Vote: I do not like it

»
7 days ago, # |
  Vote: I like it 0 Vote: I do not like it

First, part of the reason you see C++ style I/O to be slow is because you use endl, which forces the buffer to flush each time and ends up being slow.

The best way to find out the difference is to check out some benchmarks, or run your own.

»
7 days ago, # |
  Vote: I like it +1 Vote: I do not like it

Actually you only need to use "ios::sync_with_stdio(0); cin.tie(0);" without the "cout.tie(0);" because "cout" is not tied to anything.