User Input of Integers - Error Handling

后端 未结 3 1129
感动是毒
感动是毒 2020-12-03 15:47

I\'m having some trouble with certain input areas of my program. There are a few parts where the user inputs a specific integer. Even if they enter the wrong one that\'s all

3条回答
  •  心在旅途
    2020-12-03 16:35

    For a even simpler way, you can use ! operator like this:

            if ( !(cin >> room_choice) )
            {
              cin.clear();
              cin.ignore();
              cout << "Incorrect entry. Try again: ";
            }
    

提交回复
热议问题