Why would I need use fflush on stdout before writing to stderr?
问题 I am reading 'UNIX Network Programming: The Sockets Networking API' and in the example code they have an error handling function which contains the following lines: fflush(stdout); /* in case stdout and stderr are the same */ fputs(buf, stderr); fflush(stderr); Where buf contains the error description. I don't understand why fflush is used on stdout on the first line and why the comment explains the reason for its use. 回答1: This is because of buffering. Stdout and stderr are usually buffered