c++ - 如果没有\n则不会打印消息,而使用\n则打印消息

标签 c++ linux file

我编写了以下代码:

#include <sys/timerfd.h>
#include <ctime>
#include <inttypes.h>
#include <unistd.h>
#include <stdio.h>

int main()
{
    printf("Test_message");
    int tfd;
    uint64_t count;
    tfd= timerfd_create(CLOCK_MONOTONIC,0);
    itimerspec itimer;
    itimer.it_interval={1,0};
    itimer.it_value={1,0};
    timerfd_settime(tfd,0,&itimer,NULL);
    while(true)
    {
        read(tfd, &count, sizeof(count));
    }
}

当我编译和链接时,我们没有输出到控制台。但我预计Test_message将被打印。

最佳答案

  1. 运行程序。
  2. 不要忘记缓冲 - “测试消息”将是它们的,直到它被刷新。请参阅fflush

关于c++ - 如果没有\n则不会打印消息,而使用\n则打印消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23590240/

相关文章:

c++ - QTableview 属性

c++ - 无法与 libiberty 链接

Python正则表达式获取一行文本中关键字前后的n个字符

file - 从 Basecamp 导出文件

c++ - 如何销毁 CUDA 图形数据类型

c++ - 我怎样才能在 constexpr 函数中有一个临时变量?

c++ - [expr.reinterpret.cast]/6 下面的注释是什么意思?

linux - 无论服务器身份验证如何,都对 Git 存储库进行身份验证

c - 如何使用共享内存在 C Linux 中定义二维字符数组并用字符填充

c++ - 我在 C++ 中遇到 fgets 问题