twain driver什么意思:C++的一个程序1

来源:百度文库 编辑:中科新闻网 时间:2024/05/09 17:08:30
#include<iostream.h>
#include<conio.h>
void main()
{
while(1)
{
int a,b,c;
char ch;
cout<<"Please input two numbers:"<<endl;
cin>>a>>b;
c=a+b;
cout<<c<<endl;
cout<<"Continue? Y/N"<<endl;
//cin>>ch;
//if(_getch())
ch=cin.get();
if(ch=='Y'||ch=='y')
continue;
else
break;
}
}
为什么把这个程序不能循环呢!!!!!!!!!!!!
我是要能控制它的退出

把cin.get()换成getchar();

#include<iostream.h>
#include<conio.h>
void main()
{
while(1)
{
int a,b,c;
char ch;
cout<<"Please input two numbers:"<<endl;
cin>>a>>b;
c=a+b;
cout<<c<<endl;
cout<<"Continue? Y/N"<<endl;
//cin>>ch;
//if(_getch())
cin.get(); // 修改处,接受一个 回车符
ch=cin.get();//修改处,真正的接受你输入的 y 字符
if(ch=='Y'||ch=='y')
continue;
else
break;
}
}

dadalili 是乱说

mscao 是对的

>> 与 get() getline()
混合使用的时候,一定要特别注意 流里面剩余的是什么

只要不是太需要,最好用一种用到底