在 Eclipse 中 printf 之前执行的 scanf
Scanf executed before printf in Eclipse
我有以下简单的C语言代码:
#include <stdio.h>
int main(){
printf("Give an integer:\n");
int x;
scanf("%d",&x);
printf("10*%d=%d\n",x,10*x);
return 0;
}
使用 CodeBlocks IDE 它以正确的顺序执行但是当我使用 Eclipse IDE 它跳跃
到 scanf 命令,然后按原样打印消息。谁能解释一下?
提前致谢
通常 stdout
设置为 行缓冲。显然你的一个 IDE 将它设置为 fully buffered.
您可以使用 fflush()
强制打印转储相关缓冲区,例如
printf("hello "); // works in unbuffered stream
printf("world!\n"); // works in line buffered stream
fflush(stdout); // works in fully buffered stream
我有以下简单的C语言代码:
#include <stdio.h>
int main(){
printf("Give an integer:\n");
int x;
scanf("%d",&x);
printf("10*%d=%d\n",x,10*x);
return 0;
}
使用 CodeBlocks IDE 它以正确的顺序执行但是当我使用 Eclipse IDE 它跳跃 到 scanf 命令,然后按原样打印消息。谁能解释一下?
提前致谢
通常 stdout
设置为 行缓冲。显然你的一个 IDE 将它设置为 fully buffered.
您可以使用 fflush()
强制打印转储相关缓冲区,例如
printf("hello "); // works in unbuffered stream
printf("world!\n"); // works in line buffered stream
fflush(stdout); // works in fully buffered stream