cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : IOstream Library : manipulators : flush
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
IOstream Library
manipulators
classes:
· filebuf
· fstream
· ifstream
· ios
· iostream
· ios_base
· istream
· istringstream
· ofstream
· ostream
· ostringstream
· streambuf
· stringbuf
· stringstream
objects:
· cerr
· cin
· clog
· cout
types:
· fpos
· streamoff
· streampos
· streamsize
manipulators
· boolalpha
· dec
· endl
· ends
· fixed
· flush
· hex
· internal
· left
· noboolalpha
· noshowbase
· noshowpoint
· noshowpos
· noskipws
· nounitbuf
· nouppercase
· oct
· resetiosflags
· right
· scientific
· setbase
· setfill
· setiosflags
· setprecision
· setw
· showbase
· showpoint
· showpos
· skipws
· unitbuf
· uppercase
· ws

-

flush manipulator function
ostream& flush ( ostream& os );
<ostream>

Flush stream buffer

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").

The manipulator only has meaning for buffered streams, in which case it effectively calls the pubsync member of the streambuf object (rdbuf()->pubsync()) associated to the stream.

Standard output streams also have a member function with the same name and behavior (see ostream::flush).

Parameters

os
Output stream on which the insertion is performed.
Because this function is designed as a manipulator, it can be used directly with no arguments in conjunction with the insertion operator (<<) on output streams (see example).

Return Value

The same stream object on which the operation was performed (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 code is executed the content of the file test.txt is updated 100 times.

Basic template declaration

template <class charT, class traits>
  basic_ostream<charT,traits>& flush ( basic_ostream<charT,traits>& os );

See also

endl Insert newline and flush (manipulator function)
ostream::flush Flush output stream buffer (public member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us