0
我是新來的編程在C++和我面臨的問題後,lynda.com教程。在教程視頻上看起來沒問題,但這並不適合我。Printf doesnt pop
#include <stdio.h>
enum { max_string = 127 };
static char string[max_string + 1 ] = "";
int main(int argc, char ** argv) {
printf("Type a string: ");
fgets(string, max_string, stdin);
printf("The string is %s", string);
return 0;
}
當我運行這個東西空白的出現,我需要在我右像「嘿」在毯子空間,出現這種情況:
hey
Type a string: The string is hey
這是完全陌生的,我和我有不知道我在做什麼錯誤的tbh。 我使用Eclipse btw。
有人可以幫我嗎?
可能不是規範的解決方案,但在第一個'printf'語句之後添加'fflush(stdout);'應該這樣做。 – 2013-02-15 01:44:55
一個C++教程,告訴你爲用戶輸入和printf/fgets使用靜態字符數組? * Run!* – us2012 2013-02-15 01:45:06
http://stackoverflow.com/questions/1716296/why-does-printf-not-flush-after-the-call-unless-a-newline-is-in-the-format-strin – jogojapan 2013-02-15 01:47:02