Search code examples
c++bufferflush

endl and flushing the buffer


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?


Solution

  • 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.