簡體   English   中英

運行文件時保持cmd打開

[英]keep cmd open while running a file

我正在學習C ++,我正在使用Visual C ++ Express並運行它

#include <stdio.h>

int main()
{
    printf("Hello, World!\n");

    return 0;
}

cmd窗口關閉得那么快,我看不到Hello World是否有防止這種情況?

如果按Control + 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");

我只是在return語句上加了一個斷點。 沒有代碼更改。 :-)

簡單:寫這個來阻止它

getch();
i.e

main()

{

//////
Your program

/////////

getch();

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM