XCode 4只显示带有endl的cout语句

Nic*_*eet 1 c++ cout endl xcode4

我的cout语句有一个非常奇怪的问题.我只用XCode 4试过这个.例如,如果我写,

cout << "this works" << endl;
cout << "this doesnt";
cout << memorySizeLimit << " blocks of memory available." << endl;
Run Code Online (Sandbox Code Playgroud)

我在调试器控制台中看到了所有三个输出语句.但是,如果我将订单更改为,

cout << memorySizeLimit << " blocks of memory available." << endl;
cout << "this works" << endl;
cout << "this doesn't";
Run Code Online (Sandbox Code Playgroud)

我只看到前两个couts.更奇怪的是,如果我改变代码,

cout << memorySizeLimit << " blocks of memory available." << endl;
cout << "this works" << endl;
cout << "this doesn't" << endl;
Run Code Online (Sandbox Code Playgroud)

我看到了所有三个陈述.

当我改变立场时,为什么我不会看到"这不是"cout声明?

Mac*_*cky 6

std::cout是一个流,通常它是缓冲的性能.如果你打印endl流被刷新(cout << endlcout << "\n" << flush.相同).

您可以通过cout << flush(或cout.flush())手动刷新流.

所以应该打印:

cout << "this doesn't" << flush;
Run Code Online (Sandbox Code Playgroud)