iostream hierarchy flush |
cplusplus.com |
Flush buffer.
If the stream is a buffered stream, the buffer is synchronized with the physical media
associated with it.
Buffered streams are usually used when a physical device that is significantly slowlier than memory access (like files) is associated with a stream. This allows to perform the input and output operations on a memory buffer instead of directly on the device, thus accelerating considerably the operations. A call to this member function forces the stream's buffer to syncronize its data with the content of the physical device associated with it.
Parameters.
Return Value.
A reference to the stream object (parameter os).
Example.
// Flushing files (flush manipulator)
#include <fstream>
using namespace std;
int main () {
ofstream outfile ("test.txt");
for (int n=0; n<100; n++)
outfile << n << flush;
outfile.close();
return 0;
}
When this example is executed the content of the file test.txt is updated 100 times,
after each insertion.
Basic template declaration:
template <class charT, class traits> basic_ostream<charT,traits>& flush ( basic_ostream<charT,traits>& os ); |
See also.
endl,
flush function
ostream class