void main()
{
char sure;
char str[50];
cout<<"Enter the string(no more than 50 letters): "<<endl;
cin.get(str, 6);
cout<<"Any more strings?(y/n)"<<endl;
cin>>sure;
if(sure == 'y')
{
cout<<"Enter the string(no more than 50 letters): "<<endl;
cin.get(str, 6);
}}
上面代码编译执行后,在第一个cin.get()处程序会等待从屏幕输入字符到str中,然而if语句中的cin.get()却会被跳过,不知道为什么?
{
char sure;
char str[50];
cout<<"Enter the string(no more than 50 letters): "<<endl;
cin.get(str, 6);
cout<<"Any more strings?(y/n)"<<endl;
cin>>sure;
if(sure == 'y')
{
cout<<"Enter the string(no more than 50 letters): "<<endl;
cin.get(str, 6);
}}
上面代码编译执行后,在第一个cin.get()处程序会等待从屏幕输入字符到str中,然而if语句中的cin.get()却会被跳过,不知道为什么?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货