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