为什么这个没有先打印就挂起来了
Why does this hang without first printing?
为什么在没有第一次打印的情况下挂起?
#include <stdio.h>
void main() {
printf("hello world");
while (1) {}
}
因为您还没有刷新标准输出。尝试fflush
。更好的是,对于C++的使用。。。
std::cout << "hello world" << std::endl;
另外,如果您添加了n
,那么它会有更好的机会自行刷新,但并非所有实现都遵循标准。
在printf
之后调用fflush(stdout);
。
这将强制刷新和打印stdout缓冲区。
相关文章:
- 挂起和取消挂起一个文件DLL
- 如何防止C++遗留代码中的挂起指针
- 为什么所有C++编译器都会崩溃或挂起此代码
- 我编写了代码将十进制分数转换为其二进制等效数.它编译得很好,但在执行时挂起
- 构建挂起,即使是适度的文件大小
- 循环挂起迭代的 std::擦除 on std::list
- Poco::Net::FTPClientSession 在 open() 方法上挂起 129 秒,如果 ftp 主机不存
- Node.js fs.open() 在尝试打开 4 个以上的命名管道 (FIFO) 后挂起
- 从不同进程中的另一个线程挂起/恢复线程或进程
- Boost (Beast) websocket:同步写入挂起
- 为什么析构函数挂起
- 使用互斥会挂起程序
- 在C++和 Python 程序中使用命名管道的 IPC 挂起
- 设置变量时C++程序挂起
- 第一次尝试使用new动态创建结构数组,程序挂起没有错误
- 从stdin读取时子进程挂起(fork/dup2竞争条件)
- 有时ShowWindow从不调用OnShowWindow,主应用程序挂起
- 如何防止GUI挂起,同时允许第二次操作与Qt中的第一次操作一起执行
- WTSFreeMemory在启动期间从服务调用时挂起-我应该省略吗
- 当一个线程希望执行或打印某个内容时,如何挂起其他线程