简体   繁体   English

std :: cout输出直到程序结束才打印

[英]std::cout output not printed till program ends

I have a few std::cout statements and few of them do not print output to console till program ends. 我有几个std::cout语句,其中很少有人不打印输出到控制台,直到程序结束。 But it i put getchar() , it starts printing output. 但它我把getchar() ,它开始打印输出。 Why does it happen, can someone please explain? 为什么会发生,有人可以解释一下吗?

The issue may be because you are not trying to flush your output. 问题可能是因为您没有尝试刷新输出。 You can try like this: 你可以尝试这样:

std::cout << "some text" << std::flush;

or like 或者喜欢

std::cout << "some text" << std::endl;

The standard output is buffered and on newline the buffer is flushed. 标准输出是缓冲的,在换行符时刷新缓冲区。

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

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