1
为什么当输入数字时该循环执行3次?我只想''或'米'被接受..我怎么能解决这个问题?输入数字时出现循环错误
cout << "Are you married or single (m/s): ";
cin >> status;
status = tolower(status); //converting to lower case
//validating imput for marital status
while((status != 'm') && (status != 's'))
{
cout << "Sorry, you must enter \"m\" or \"s\" \n"
<< "Are you married or single (m/s): ";
cin >> status;
status = tolower(status);
}
你应该说明的是3,可能是因为 “一\ r \ n” 个 –
'\ r \ n'应该被流自动转换为'\ n'(我想'cin'自动处于文本模式)... –
只有当它没有任何空格时才会得到整行输入。 .. – sth