c++fflushcstdio

What is fflush exactly and what does it do?


I was reading http://www.cplusplus.com/reference/cstdio/fflush/ and I was curious about what it means. According to the website it says:

If the given stream was open for writing (or if it was open for updating and the last i/o operation was an output operation) any unwritten data in its output buffer is written to the file.

What does the output buffer to file mean?


Solution

  • Some streams buffer output data and do not write to the device immediately. fflush forces the contents of the stream's buffer, if there is one, to be written to the device and the buffer cleared.