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;
}

相关文章:

  • 2022-12-23
  • 2021-12-23
  • 2022-12-23
  • 2021-07-09
  • 2021-05-16
  • 2021-12-12
  • 2021-10-02
  • 2022-12-23
猜你喜欢
  • 2021-09-20
  • 2022-12-23
  • 2021-10-04
  • 2021-05-05
  • 2023-01-12
  • 2021-09-26
相关资源
相似解决方案