I have frequently encountered people writing in their c++ code ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
. I do not understand what exactly is the reason of printf()
and scanf()
being faster than cout
and cin
. I understand that cout
and cin
are streams and not functions. However, I am more curious to know what is the underlying mechanism which makes cout
and cin
slower than printf()
and scanf()
.
Asked
Active
Viewed 790 times
1

Jonathan Leffler
- 730,956
- 141
- 904
- 1,278

Pikachu
- 304
- 3
- 14
-
1`cin` and `cout` are tied together by default. Performing a read on `cin` first flushes `cout` if it has buffered data waiting to be output. C functions like `printf()` and `scanf()` are not similarly tied together – Remy Lebeau Jan 24 '20 at 06:10
-
1[This post](https://stackoverflow.com/questions/896654/cout-or-printf-which-of-the-two-has-a-faster-execution-speed-c) can be helpful. – Yunus Temurlenk Jan 24 '20 at 06:14