FLUSH()

The flush() function forces the output buffer of a stream to be written immediately to the associated file or device without closing the stream. Normally, output is buffered for efficiency, meaning it may remain in memory before being written to disk. By calling flush(), you ensure that all pending data is saved right away while keeping the file open for further writing. This is particularly useful in scenarios where data integrity is critical, such as logging or real-time output, because it prevents loss of information if the program crashes or is interrupted. Unlike close(), flush() does not release the file handle; the file remains open and usable.

Last updated