Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library User's Guide

35.3 Implicit Synchronization Using the unitbuf Format Flag

You can achieve a kind of automatic synchronization for output files by using the format flag ios_base::unitbuf. It causes an output stream to flush its buffer after each output operation as follows:

//1Set the unitbuf format flag.
//2After each insertion into the file /tmp/fil, the buffer is automatically flushed, and the output is available to other streams that read from the same file.

Since it is not overly efficient to flush after every single token that is inserted, you might consider switching off the unitbuf flag for a lengthy output that is not supposed to be read partially.

//1Switch off the unitbuf flag. Alternatively, using manipulators, you can use ostr << std::ios_base::nounitbuf;
//2Flush the buffer and switch on the unitbuf flag again. Alternatively, you can use the std::ios_base::flush and std::ios::base::unitbuf manipulators.


Previous fileTop of DocumentContentsIndex pageNext file