endl and flushing the buffer

Simplicity picture Simplicity · Jan 20, 2011 · Viewed 21.7k times · Source

In the C++ primer book, in chapter (1), it mentions the following:

endl is a special value, called a manipulator, that when written to an output stream has the effect of writing a newline to the output and flushing the buffer associated with that device. By flushing the buffer, we ensure that the user will see the output written to the stream immediately.

What is meant by "flushing the buffer" here?

Answer

Benjamin Lindley picture Benjamin Lindley · Jan 20, 2011

Output is generally buffered before it's written to the intended device. That way, when writing to slow to access devices(like files), it doesn't have to access the device after every single character.

Flushing means emptying the buffer and actually writing it to the device.