I have a really weird issue with my cout statements. I’ve only tried this out with XCode 4. For instance, if I write,
cout << "this works" << endl;
cout << "this doesnt";
cout << memorySizeLimit << " blocks of memory available." << endl;
I see all three output statements in my debugger console. However, if I change the order to,
cout << memorySizeLimit << " blocks of memory available." << endl;
cout << "this works" << endl;
cout << "this doesn't";
I only see the first two couts. Even stranger, if I change the code to,
cout << memorySizeLimit << " blocks of memory available." << endl;
cout << "this works" << endl;
cout << "this doesn't" << endl;
I see all three statements.
Why would I not see that “this doesn’t” cout statement when I change its position?
std::coutis an stream and normally it is buffered for performance. If you printendlthe stream gets flushed (cout << endlis the same ascout << "\n" << flush.You may flush the stream manually by
cout << flush(orcout.flush()).So that should print: