C++ Ostream Library - flush



Description

It is used to flush output stream buffer and synchronizes the associated stream buffer with its controlled output sequence.

Declaration

Following is the declaration for std::ostream::flush.

ostream& flush();

Parameters

none

Return Value

It returns the ostream object (*this).

Exceptions

Basic guarantee − if an exception is thrown, the object is in a valid state.

Data races

Modifies the stream object.

Example

In below example explains about std::ostream::flush.

#include <fstream>

int main () {

   std::ofstream outfile ("test.txt");

   for (int n=0; n<100; ++n) {
      outfile << n;
      outfile.flush();
   }
   outfile.close();

   return 0;
}
ostream.htm
Advertisements