Eclipse用的顺手了,学习C的时候也不想使用别的编辑器了,但是却发现一个问题,描述如下:
程序段:
正常的输出应该为:
[i]Please input the value of number : (光标停顿,等待输入,例如输入15,回车)
The value of number is :15[/i]
但是用Eclipse后发现,输出的结果是
[i](光标停顿,等待输入,例如输入15,回车)
Please input the value of number :The value of number is :15[/i]
经过大量测试发现,总是先把所有的输入工作完成后,控制台中才全部输出。在eclipse的官网上找到了答案,大概是这样说的。这并不是CDT的问题,而是你采用的C语言的库的问题,通常的C的输入输出库使用了带缓冲的输入输出,所以 printf 的内容还没有从缓冲中输出。实际在写代码的时候在每句 printf 的后面加上一句“fflush(stdout);"就可以了。
程序段:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int c = 0;
printf("Please input the value of number : ");
scanf("%d", &c);
printf("The value of number is : %d", c);
return 0;
}
正常的输出应该为:
[i]Please input the value of number : (光标停顿,等待输入,例如输入15,回车)
The value of number is :15[/i]
但是用Eclipse后发现,输出的结果是
[i](光标停顿,等待输入,例如输入15,回车)
Please input the value of number :The value of number is :15[/i]
经过大量测试发现,总是先把所有的输入工作完成后,控制台中才全部输出。在eclipse的官网上找到了答案,大概是这样说的。这并不是CDT的问题,而是你采用的C语言的库的问题,通常的C的输入输出库使用了带缓冲的输入输出,所以 printf 的内容还没有从缓冲中输出。实际在写代码的时候在每句 printf 的后面加上一句“fflush(stdout);"就可以了。