我已尝试过下面的功能,
string checkstring(int sublen){
bool quit = false;
string temp;
while(!quit){
cin>>temp;
if (temp.size()> sublen){
cout<<"\t"<<"Error , Only "<<sublen<<"characters are allowed "<<endl;
cin.clear();
getch();
}else{
return temp;
quit=true;
}
}
}
问题是,如果我在输入字符串中输入任何数字,它会跳过几行。
Ex: - 输入您的姓氏:Mayer 23,
它从循环中跳过下一个问题
Question Marked with blue has skipped - Please view thus image | Cursor at Red Mark
抱歉我的英语不好!请帮助!