User Input of Integers - Error Handling

后端 未结 3 1117
感动是毒
感动是毒 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:34

    You can use cin.good() or cin.fail() to determine whether cin could successfully deal with the input value provided. You can then use cin.clear(), if necessary, to clear the error state before continuing processing.

提交回复
热议问题