printf的不打印在控制台上 [英] printf not printing on console
问题描述
我入门C语言。我使用的Eclipse(JUNO)作为我的IDE和安装CDT插件。我也将解压缩mingw64(GCC编译)。我写了一个非常简单的程序,看看它是否工作。这是我的code:
I’m getting started in the C language. I am using eclipse (juno) as my IDE and installed CDT plugin. I have also unpacked mingw64 (GCC Compiler). I wrote a very simple program to see if it works. This is my code:
#include <stdio.h>
int main()
{
int age;
printf("Hello, please enter your age:\n");
scanf("%d", &age);
printf("Your age is %d", age);
return 0;
}
问题是,输出缓冲器填充有第一的printf
但不输出到控制台的字符串值。我必须输入一个数字,然后才缓冲区中的所有数据倒到控制台,所以我看到控制台是这样的:
The problem is that the output buffer is filled with the string value of the first printf
but does not output it to the console. I have to enter a number, and only then the buffer pours all the data to the console so I see the console something like this:
1
Hello, please enter your age:
Your age is 1
代替期望是什么是:
instead of what is expected that is:
Hello, please enter your age:
1
Your age is 1
现在,我发现我可以使用 fflush(标准输出)
后的第一个的printf
但我不认为这个解决方案是优雅的,甚至是必要。我如何能解决这个任何想法?
Now, I found that I can use fflush(stdout)
after the first printf
but I don't think that this solution is elegant and even necessary. Any ideas on how I can overcome this?
修改 - 因为我正在学习这在我的大学,我不能使用任何没有在课程中所学,所以我可以的仅使用的printf
和 scanf函数
EDIT - because I'm learning this in my university, I can't use anything that wasn't learned in the course so I can only use printf
and scanf
新修改 - 我想我已经找到了这种解释。正如我所说的,我输出到Eclipse内部控制台视图。奇怪的是,如果我编译和从Windows的命令行运行程序,我得到的通缉的结果。因此,我认为,Eclipse是实际编写输出到文件和presenting它在控制台窗口。我怎么可以强制Eclipse在我的运行配置打开一个真正的命令行窗口?
NEW EDIT - I think I have found an explanation for this. As I said, I am outputting to the console view inside Eclipse. The strange thing is that if I compile and run the program from the command line of Windows, I get the wanted result. Therefore, I think that eclipse is actually writing the output to a file and presenting it in the console window. How can I force eclipse to open a real command line window in my run configurations?
推荐答案
确定 - 显然这是日食的一个已知的bug。此错误与WONT-FIX的决议决定。
不知道为什么,虽然。这里是链接:
的Eclipse。c控制台错误
OK - apparently this is a known bug of eclipse. This bug is resolved with the resolution of WONT-FIX.
have no idea why though. here is the link:
Eclipse C Console Bug
这篇关于printf的不打印在控制台上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!