c++ press any key to continue

来源:百度知道 编辑:UC知道 时间:2024/09/21 20:33:44
每次运行C++程序之后都会出现“press any to continue”请问怎样不让它出现这句话?如何在程序执行一次之后不立即结束程序而可以继续进行下一次运作?

呵呵,首先在编译的时候不论怎么,都是会出的,没办法的,你只能对它说:
I DON'T WANT CONTINUE 呵呵

你后面这个问题可以用很多中方法实现:
do{} while 例如:我遍了个程序,要别人输入一个小于等于10的数,结果别人就喜欢和我过不去,输入一个大于10的数,想看看程序会怎么样,先看原程序:
#include <iostream>
using namespace std;
int main()
{
int m;
cout<<"pleace enter one number:";
cin>>m;
if(m>10)cout<<"别和我过不去\n";
else cout<<m+10<<endl;
return 0;
}
看这个程序一旦我输入大于10的数就会出现:别很我过不去press any to continue
现在用do{} while来做看一下:
#include <iostream>
using namespace std;
int main()
{
int m,ans=0;//申明
cout<<"pleace enter one number:";
cin>>m;
do
{
if(m>10)
{
cout<<"别和我过不去\n";
cout<<"你是否还要继续 Y/N?"
cin>>ans;
}
else cout<<m+10<<endl;
}while(ans=='y'||ans=='Y');
return 0;
}
这下就可以重来了,呵