There's a great discussion on this over here.
From one of the answers:
Every C++ stream uses an associated stream buffer object to perform buffering.
When std::cout
is constructed, it uses the stream buffer associated with the object stdout
, declared in <cstdio>
.
By default, operations on std::cout
can be freely mixed with <cstdio>
output functions like std::printf()
.
In practical terms, synchronization usually means that a standard iostream object and a standard stdio object share a buffer. - IS
If std::ios_base::sync_with_stdio(false)
is called (before any input or output operations on the standard streams), the standard C++ streams operate independently of the standard C streams (ie. they switch to their own separate stream buffers).
For more, see the sync_with_stdio
function reference page on cppreference.
From that page, the function...
Sets whether the standard C++ streams are synchronized to the standard C streams after each input/output operation.
...In practice, this means that the synchronized C++ streams are unbuffered, and each I/O operation on a C++ stream is immediately applied to the corresponding C stream's buffer. This makes it possible to freely mix C++ and C I/O.
However, beware of calling this function after there have already been reads or writes:
If this function is called after I/O has occurred on the standard stream, the behavior is implementation-defined: implementations range from no effect to destroying the read buffer.
std::ios::sync_with_stdio(false);
before you print. – Mccaskill