简体   繁体   English

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

[英]XCode 4 only displaying cout statements with endl

I have a really weird issue with my cout statements. 我的cout陈述有一个很奇怪的问题。 I've only tried this out with XCode 4. For instance, if I write, 我仅使用XCode 4进行了尝试。例如,如果我编写了代码,

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? 更改立场时,为什么我看不到“ this not” cout语句?

std::cout is an stream and normally it is buffered for performance. std::cout是流,通常对其进行缓冲以提高性能。 If you print endl the stream gets flushed ( cout << endl is the same as cout << "\\n" << flush . 如果您打印endl ,流将被刷新( cout << endlcout << "\\n" << flush

You may flush the stream manually by cout << flush (or cout.flush() ). 您可以通过cout << flush (或cout.flush() )手动刷新流。

So that should print: 所以应该打印:

cout << "this doesn't" << flush;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM