我有以下简单的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将其设置为完全缓冲。
您可以用fflush()
强制打印以转储关联的缓冲区,例如
putchar('s'); // works in unbuffered stream
printf("omething\n"); // works in line buffered stream
fflush(stdout); // works in fully buffered stream