我創建了一個簡單的.exe文件。當我運行它時,它會自動關閉,而不是說「按任意鍵退出」。程序自動退出
這是我的計劃:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string answer, yes = "yes";
cout << "Is Lucy a top lass ? enter yes or no" << endl;
cin >> answer;
if (answer == yes)
{
cout << "Correctomundo" << endl;
}
else
{
cout << " Blasphemy ! " << endl;
}
return 0;
}
我如何使它詢問用戶在退出之前按任意鍵?
也有什麼辦法可以改變它,所以它說別的東西,而不是「按任意鍵退出」?
回報 – anoop
這是正常的行爲控制檯前面加上'殘培()'末應用。我會建議反對像一個非標準的程序。如果你想要一個持久的控制檯窗口,首先打開命令提示符窗口並通過它運行你的程序。 – jamesdlin
當我這樣做時,我得到以下內容: - 錯誤\t C3861 \t'getch':標識符未找到。你能解釋這是爲什麼嗎? –