Buffered and Unbuffered
- Buffered - All output is temporarily stored in a buffer and then dumped to screen in one go. Both cout and clog are buffered.
- Unbuffered- All output goes immediately to the output device. An example of an unbuffered object is cerr.
The main problem with buffering, is if the program crashes then the buffer contents are lost and it's harder to see why it crashed. Unbuffered output is immediate so sprinkling a few lines like this through the code might come in useful.
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{ cerr.width(15) ;
cerr.right;
cerr << "Error" << endl;
return 0;
}
cerr << "Entering Dangerous function zappit" << endl;
The Logging Problem
Building a log of program events can be a useful way to spot difficult bugs- the type that only occur now and then. If that event is a crash though, you have the problem- do you flush the log to disk after every call so you can see events right up to the crash or keep it in a buffer and periodically flush the buffer and hope you don't lose too much when the crash occurs?There is an alternative method. Use a 3rd party application to log events. I've put this in a quick tip How to Debug Windows Applications Without a Debugger.
On the next page : Using cin for input

