Question:
what is the use of flush() function in c++?
2011-02-04 00:44:11 UTC
i cant compile when i use flush() function
Three answers:
tomejuan
2011-02-04 00:47:50 UTC
Flushing is used to empty the buffer of a buffered stream.



Assuming you were using an output stream, a set amount of information is transferred to a buffer before being flushed and written to an external data store (a file). The benefits of a Buffered stream is that it is faster and more efficient as writing to the disk costs memory so doing it in larger batches with the help of a buffer is useful.



The flush function manually flushes the buffer. You may wish to do this when closing an application to ensure there is no left over information in the buffer.
tbshmkr
2011-02-04 11:22:13 UTC
flush()

=

Synchronizes the buffer associated with the stream to its controlled output sequence. This effectively means that all unwritten characters in the buffer are written to its controlled output sequence as soon as possible ("flushed").

- http://www.cplusplus.com/reference/iostream/ostream/flush/

-

Post the source code / error msg for specific help.
2011-02-04 08:46:20 UTC
to empty the crap of course!

More seriously it synchronizes the buffer associated with the stream to its controlled output sequence.

Remember, the function only has meaning for buffered streams


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...