使用GCC 5.1.0编译器在eclipse CDT上尝试此代码时
所有字符串都是在用户输入之后打印的。。
当在Visual Studio和代码块ide上编译它时,即使使用windows CMD,程序也能正常工作。。

‪#‎include‬ <stdio.h>
static char string[128] = "";
int main() {
printf("Type a string: ");
scanf("%s",string);
printf("The String is %s", string);
return 0;
}

Eclipse输出:
c - 编译C程序后Eclipse CDT意外输出-LMLPHP
Visual Studio输出:
c - 编译C程序后Eclipse CDT意外输出-LMLPHP
谢谢,,,

最佳答案

好吧,我明白了。我认为问题在于,每当您想确定代码中的某个给定点打印了某个内容时,就需要在该点刷新stdout
否则,流式内容可以按依赖于实现的方式(通常是小批量)排队和交付
C标准库的printf()在输出到stdout并遇到换行符时提供隐式刷新,因此您不需要自己调用\n。而C++的flush(),只有std::cout具有此属性;不能保证std::endl
在C中故意刷新\n可以这样做:stdout
另请参见:Why does printf not flush after the call unless a newline is in the format string?

关于c - 编译C程序后Eclipse CDT意外输出,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31706037/

10-11 23:12
查看更多