0
// Validation and entry for ticket price
void ValidateTicketPrice (double &ticket_price){
string error_string;
cin >> ticket_price;
while(1)
{
if(cin.fail())
{
cin.clear();
getline (cin, error_string);
cout << error_string << " is not a valid ticket price. Please re-enter the data: ";
cin >> ticket_price;
} else {
Flush();
break;
}
}
}
您的預期輸出是什麼,您的輸入是什麼不起作用?我測試了你的代碼片段,它對我來說似乎很好。 –
Getline無法獲取已獲取的數據。清除將刪除錯誤狀態,但不允許您從流中重新獲取數據。 – user4581301