所以我必须能够验证用户输入并确保它是 y 或 n 出于某种原因它没有给我它并且它正在向 while 循环的主体发送垃圾邮件。请帮助。谢谢
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;
}