flush()
is called in these situations:
- When
std::endl
is used (namely an explicit call tostd::ostream::flush()
) [§27.7.3.7/7] - When the stream's destructor is called [§27.5.3.1.6/4]
- When the stream to which it is
tie()
-ed performs a read. [§27.7.2.1.3/2] - When the file stream is repositioned.
- When the stream has reached the maximum allocated characters in its buffer, when
overflow()
is called to extract the content to the external device, [§27.6.3.4.5/3] - or in the case of input streams, when
gptr() == egptr()
, a call tounderflow()
to discard the content and synchronize its buffer with the external device. [§27.6.3.4.3/7]
This is what I know about the standard IOStreams. This could vary depending on the implementation of your stream or stream buffer.