1. 程式人生 > >vs下程式執行結果框閃退的三種解決方案

vs下程式執行結果框閃退的三種解決方案

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)“

最後程式會執行成這個樣子

加油!!