1.getchar()
在return 0 之前一行getchar();因爲getchar()會一直等待用戶輸入
#include <iostream>
using namespace std;
int main() {
cout << "hello world!" << endl;
getchar();
return 0;
}
2.在程序末尾添加語句:system("pause"); 再加上頭文件#include <stdlib.h>,這樣運行結果後就會顯示結果,並提示“請按任意鍵繼續”
#include <iostream>
#include <stdlib.h>
using namespace std;
int main() {
cout << "hello world!" << endl;
return 0;
system("pause");
}
3.修改項目配置,右鍵點擊項目,在右鍵菜單中選擇屬性,然後在彈出的對話框左側列表中選擇“配置屬性”-->“鏈接器”-->“系統”,然後在右側的列表中,在第一項”子系統“的值中選擇”控制檯(/SUBSUSTEM:CONSOLE)“
最後程序會運行成這個樣子
加油!!