XCode 4仅显示带有endl的cout语句 [英] XCode 4 only displaying cout statements with endl

查看:179
本文介绍了XCode 4仅显示带有endl的cout语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的cout语句确实有一个很奇怪的问题.我仅使用XCode 4进行过尝试.例如,如果我编写了

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;

我看到所有三个陈述.

为什么更改位置时我看不到"this not" cout语句?

Why would I not see that "this doesn't" cout statement when I change its position?

推荐答案

std::cout是流,通常对其进行缓冲以提高性能.如果打印endl,流将被刷新(cout << endlcout << "\n" << flush相同.

std::cout is an stream and normally it is buffered for performance. If you print endl the stream gets flushed (cout << endl is the same as cout << "\n" << flush.

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

You may flush the stream manually by cout << flush (or cout.flush()).

因此应该打印:

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

这篇关于XCode 4仅显示带有endl的cout语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆