In C++, you can control (with cin.tie
) whether the cin stream is tied to the cout stream (i.e. if cout will flush whenever you have to read from cin). By default, this is true and it is useful for interactive programs (if you output a promt and then expect input, the prompt is guaranteed to be flushed on screen). But it can make a program slower due to unnecessary flushes.
Is there an equivalent way to control the synchronization between stdin and stdout when using plain C and <stdio.h>
? Is there any guarantee about the default behavior?
(I've noticed most compilers do seem to tie stdin with stdout, but I haven't seen anything about it in the standard.)