devxlogo

fflush()

fflush()

Question:
I am having difficulty finding information and examples on how to use the flush function.

Answer:
If you are not sure how to use this function, then you probably don’t need it. Most C/C++ programs do not need to use this function.

To make file access faster, many run-time library routines will read and write a fixed number of bytes at a time. This means that if you write one byte at a time, the functions will wait until an internal buffer is full and write it all at once, which is considerably faster than going to disk for each byte.

Normally, this is done transparently and there is no reason to flush a file as it is automatically flushed when the file is closed.

devx-admin

Share the Post: