std :: cout将不打印 [英] std::cout won't print

查看:572
本文介绍了std :: cout将不打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有任何情况下, std :: cout<< hello不工作?我有一个c / c ++代码,但是 std :: cout 不打印任何东西,甚至不是常量字符串(如hello)。

Is there any circumstance when std::cout << "hello" doesn't work? I have a c/c++ code, however the std::cout doesn't print anything, not even constant strings (such as "hello").

有没有办法检查 cout 能否/无法打开流?有一些成员函数如 good() bad(),...但我不知道一个适合我。

Is there any way to check if cout is able/unable to open the stream? There are some member functions like good(), bad(), ... but I don't know which one is suitable for me.

推荐答案

确保您刷新流。这是必需的,因为输出流是缓冲的,并且您无法保证缓冲区何时被刷新,除非您自己手动刷新。

Make sure you flush the stream. This is required because the output streams are buffered and you have no guarantee over when the buffer will be flushed unless you manually flush it yourself.

std::cout << "Hello" << std::endl;

std :: endl 并刷新流。或者, std :: flush 将会只是做flush。也可以使用stream的成员函数进行刷新:

std::endl will output a newline and flush the stream. Alternatively, std::flush will just do the flush. Flushing can also be done using the stream's member function:

std::cout.flush();

这篇关于std :: cout将不打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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