【问题标题】:printf not printing in console in eclipse cprintf不在eclipse c的控制台中打印
【发布时间】:2014-11-02 02:07:51
【问题描述】:

我刚刚开始在 Eclipse 上运行,我似乎遇到了 printf() 语句的问题。我运行了一段在 Notepad++ 中工作的基本代码,但在 Eclipse 中似乎没有做同样的事情。编译并运行程序后,下面的控制台中似乎没有打印任何内容。我的代码、IDE 或其他方面有问题吗?

#include<stdio.h>


int main (void)
{
    printf("Hello world");
    fflush(stdout);

    return 0;
}

【问题讨论】:

  • 在哪个操作系统上使用哪个编译器? Eclipse 只是一个美化的编辑器....
  • 版本:Juno Service Release 1。操作系统:Windows 7
  • 但是使用哪个编译器?尝试在命令行上运行你的编译器(Eclipse 在内部这样做)。
  • 想法:1) 尝试fputs("Hello world\n", stderr); 2) 写入磁盘文件 3) Eclipse 设置不正确。

标签: c eclipse


【解决方案1】:

此链接可能会有所帮助

Why does printf not flush after the call unless a newline is in the format string?

尝试在 printf 中添加 '\n'。

printf("Hello world\n");

【讨论】:

  • 感谢您的建议,但仍然没有运气。即使添加了 \n,控制台在运行后仍然是空的。
  • setvbuf (stdout, NULL, _IONBF, 0);如果仍有问题,请尝试在 printf 之前添加。*.com/questions/13035075/…