原
VS 2017 C++ 运行完程序后迅速关闭窗口(不让窗口一闪而过的方法)——解决办法
方法一
在 return 0; 语句前面添加一句:system("pause"); 下面是测试程序;
-
#include<iostream>
-
int main()
-
{
-
using
namespace
std;
-
cout <<
"Come up and C++ me some time.";
-
cout <<
endl;
-
cout <<
"You wont't regert it!" <<
endl;
-
system(
"pause");
-
return
0;
-
}
运行结果:
需要添加头文件#include stdlib.h
方法二
在 return 0; 语句前面添加一句:cin.get(); 下面是测试程序;
-
#include<iostream>
-
int main()
-
{
-
using
namespace
std;
-
cout <<
"Come up and C++ me some time.";
-
cout <<
endl;
-
cout <<
"You wont't regert it!" <<
endl;
-
cin.get();
-
return
0;
-
}
运行结果:
方法三
安装使用Visual Studio 2017 后,用Ctrl+F5运行程序,结果控制台窗口一闪就没了,也没有出现”press any key to continue…” 或者“请按任意键继续”。 出现这种原因,主要是建立工程时选用的是“空工程(Empty Project)”,而不是“Win32控制台程序(Win32 console application)”。
此时,只需要选择“项目”>"属性“>就会出现如下图所示,然后选择”系统“>"子系统”,将“子系统”改为“控制台(/SUBSYSTEM:CONSOLE);就可以顺利解决了