DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
iostream examples

Flushing

In many circumstances the iostream library accumulates characters so that it can send them to the ultimate output consumer in larger (presumably more efficient) chunks. This is a problem mainly in interactive programs where the user may need to see the output before entering input. It can also be a problem during debugging when the programmer may need to see how far the program has gotten before dumping core. The easiest way to make sure that everything inserted into an ostream has been sent to the ultimate consumer is to insert a special value, flush. For example:

   cout << "Please enter date:" << flush ;
Inserting flush into an ostream forces all characters that have been previously inserted to be sent to the ultimate consumer of the ostream. flush is an example of a kind of object known as a manipulator, a value that may be inserted into an ostream to have some effect. It is really a function that takes an ostream& argument and returns its argument after performing some actions on it.

Another useful way to cause flushing is the endl manipulator, which inserts a newline and then flushes.

   cout << "x=" << x << endl ;

Next topic: Binary output
Previous topic: Propagating errors

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005