我學習C++和我使用Visual C++ Express和同時運行這保持CMD打開,而運行的文件
#include <stdio.h>
int main()
{
printf("Hello, World!\n");
return 0;
}
cmd窗口關閉如此之快,我無法看到的Hello World 是無論如何,以防止這一點?
我學習C++和我使用Visual C++ Express和同時運行這保持CMD打開,而運行的文件
#include <stdio.h>
int main()
{
printf("Hello, World!\n");
return 0;
}
cmd窗口關閉如此之快,我無法看到的Hello World 是無論如何,以防止這一點?
如果按Ctrl + F5,你將不會被調試器附着 - 然而,它會留在一個「按任意鍵繼續」風格郵件打開。
在返回之前放置一個getc()。只有按任意鍵時,程序纔會關閉。
是的常見解決方案是添加一個從鍵盤讀取輸入的語句。這個調用會阻止執行,直到按下某個鍵。你可以用語句做到像
printf("Hit \"Enter\" to continue\n");
fflush(stdin); /* Remove anything that is currently in the standard input */
getchar(); /* Wait for the user to hit the enter key */
,你可以在主月底鍵入:
system("pause");
簡單: 寫這阻止它
getch();
i.e
main()
{
//////
Your program
/////////
getch();
}
+1我從來沒有想過它:( – AraK 2009-09-02 00:24:14
感謝小費 – Raptrex 2009-09-02 00:46:48