Conventionally, std::cin, std::cout are buffererd and std::cerr is not buffered. Unbuffered streams are written to device immediately. In general, ofstreams are buffered. You can make a stream unbuffered by invoking setbuf(0,0).
of.setbuf(0,0); // makes it unbuffered.
You can force a buffered stream to flush the contents using std::endl. Other interesting thing is to tie an buffered output stream with a buffered input stream. What this means is, whenever you want to accept an input from the input stream, the output stream 'tied' to it is flushed automatically.
ifstream in; // a buffered input stream.
ofstream out; // a buffered output stream.
and in and out are tied together.
out << "data 1" << "data 2" << ..... << "data N";
// may or may not occur on screen or file.
in >> somevar; // out will be flushed before somevar is input.
You do this by invoking:
tie causes two streams to be synchronized, such that, operations on one stream occur after operations on the other stream are complete. As a last note, by default, the standard objects cin, cerr and clog are tied to cout.