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().
cinandcoutare tied together by default. Performing a read oncinfirst flushescoutif it has buffered data waiting to be output. C functions likeprintf()andscanf()are not similarly tied together