1
SoI必须能够验证用户输入,并确保它是因为某种原因它不会给我,它是垃圾邮件正在while循环..请help.Thanks验证Char功能
char getCharChoice(string message, char y, char n)
{
char choice;
// Print the message and get the input
cout<<message<< " ";
cin>>choice;
// Check for valid input
while (choice != y || choice != n)
{
cin.clear(); // reset the input stream
cin.ignore(5000, '\n'); // take any remaining input off the stream
// Ask for a choice and read user input
cout << "Not a valid input please: Choose y or n: ";
cin >> choice;
}
return choice;
}
谢谢你是正确的我搞砸了。非常感谢你 – 2013-04-24 22:25:07