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

最后程序会运行成这个样子

加油!!

猜你喜欢

转载自blog.csdn.net/jfwzy109127/article/details/84190329