C++中string类的问题。
在string中用getline(cin,str)输入,运行中总是按两次回车,但是后面的数据就不对了,应该怎样改正????#include<iostream>#inclu...
在string中用getline(cin,str)输入,运行中总是按两次回车,但是后面的数据就不对了,应该怎样改正????
#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;
void main()
{
int n;
string str;
while(1)
{
cout<<"input n"<<endl;
getline(cin,str);
n=atoi(str.c_str());
switch(n)
{
case 21:
{
cout<<n<<endl;
}break;
case 0:
{
cout<<"wrong number !"<<endl;
}break;
case 1:
{
return;
}break;
default:
{
cout<<"** wrong number !"<<endl;
}
}
}
} 展开
#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;
void main()
{
int n;
string str;
while(1)
{
cout<<"input n"<<endl;
getline(cin,str);
n=atoi(str.c_str());
switch(n)
{
case 21:
{
cout<<n<<endl;
}break;
case 0:
{
cout<<"wrong number !"<<endl;
}break;
case 1:
{
return;
}break;
default:
{
cout<<"** wrong number !"<<endl;
}
}
}
} 展开
展开全部
#include<iostream>
#include<string>
#include<stdlib.>
using namespace std;
void main()
{
int n;
string str;
while(1)
{
cout<<"input n"<<endl;
getline(cin,str);
n=atoi(str.c_str());
switch(n)
{
case 21:
{
cout<<n<<endl;
}break;
case 0:
{
cout<<"wrong number !"<<endl;
}break;
case 1:
{
return;
}break;
default:
{
cout<<"** wrong number !"<<endl;
}
}
}
}
#include<string>
#include<stdlib.>
using namespace std;
void main()
{
int n;
string str;
while(1)
{
cout<<"input n"<<endl;
getline(cin,str);
n=atoi(str.c_str());
switch(n)
{
case 21:
{
cout<<n<<endl;
}break;
case 0:
{
cout<<"wrong number !"<<endl;
}break;
case 1:
{
return;
}break;
default:
{
cout<<"** wrong number !"<<endl;
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询