C++ 检查输入是否为特定类型且在特定范围内

C++ 检查输入是否为特定类型且在特定范围内,c++,while-loop,C++,While Loop,我正在尝试测试用户输入的内容,这样我的程序就不会中断。我使用的线路是: while (check != 0){ cout << "Please enter a number 1 - 4 (area of: circle, rectangle, triangle or quit)" << endl; cin >> response; if ((isdigit(response)) && ((response >=

我正在尝试测试用户输入的内容,这样我的程序就不会中断。我使用的线路是:

while (check != 0){
    cout << "Please enter a number 1 - 4 (area of: circle, rectangle, triangle or quit)" << endl;
    cin >> response;


    if ((isdigit(response)) && ((response >= 1) && (response <= 4))){
        check = 0;

    }
    else{
        cout << "You did not enter a valid digit (1 - 4)" << endl;
        check = 1;
    }

} // End of while loop
while(检查!=0){
cout反应;

如果((isdigit(response))&&((response>=1)&&&(response假设
response
类型为
char
,则需要使用字符常量
'1'
'4'
,而不是整数常量
1
4

if ((isdigit(response)) && ((response >= '1') && (response <= '4'))){

if((isdigit(response))&&((response>='1')&&(response
if(response>='1'&&response您的方法到底出了什么问题?什么是
检查
?什么是
响应
?您知道流可以用于检查它是否成功?最后一位意味着您可以将
响应
声明为
int
,并执行类似
if(!(cin>>响应)的操作| |!介于(响应,1,4))
之间。为什么不在(1)
时说
,然后当用户输入有效时,使用
break
语句?噢,谢谢。我完全忘了isdigit是字符值。我会√ 10分钟后回答这个问题。