首页 > 编程语言 > 详细

c++为什么代码执行性后出现一个黑框(命令窗口)一闪而过解决办法

时间:2015-04-15 19:01:25      阅读:818      评论:0      收藏:0      [点我收藏+]
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;
}

c++为什么代码执行性后出现一个黑框(命令窗口)一闪而过解决办法

原文:http://www.cnblogs.com/wangxiaochu/p/4428971.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!