c++为什么代码执行性后出现一个黑框(命令窗口)一闪而过解决办法
VS2012 输入代码执行后屏幕一闪而过不出现显示框:
#include <iostream>
int main ()
{
using namespace std;
const int ArSize = 20;
char name[ArSize];
char dessert[ArSize];
cout <<"Enter your name:\n";
cin.getline(name,ArSize);
cout <<"Enter your favorite dessert:\n";
cin.getline(dessert,ArSize);
cout <<"I have some delicious "<<dessert;
cout <<"for you,"<<name<<".\n";
return 0;
}
没有出现黑框(命令行窗口)事因为执行完...cout <<"for you,"<<name<<".\n";之后直接return 0,即执行完了,所以会关闭,所以可以在return之前加个system("pause");就可能观察输出情况了。改后程序如下:
#include <iostream>
int main ()
{
using namespace std;
const int ArSize = 20;
char name[ArSize];
char dessert[ArSize];
cout <<"Enter your name:\n";
cin.getline(name,ArSize);
cout <<"Enter your favorite dessert:\n";
cin.getline(dessert,ArSize);
cout <<"I have some delicious "<<dessert;
cout <<"for you,"<<name<<".\n";
system("pause");
return 0;
}