Originally posted by Rebecca Witmer:
I thought flushing was just sort of a way to get it unclogged if it was trying to hold too much stuff at once before writing the stuff to a file.
The buffer will flush() itself for vaious reasons, most notably when it gets full. You can call flush() yourself if you want whatever might still be buffered to be written immediately. Finally, closing the stream flushes the buffer.
To clarify then, you never
need to call flush(), but you may. Usually you would do this if some other process is reading from the file/socket to which you're writing and you want to make sure they aren't waiting for your buffer to flush() itself.