相关问题:
我发现一个similar问题已经在此处发布在stackoverflow上,但是由于某种原因,该问题对我而言不起作用。
我的问题:
当我输入非整数值时,无法在以下代码中跳出循环。
int main(){
int num;
do {
cout << endl << "\tEnter number (enter anything other than a number to exit): ";
try{
cin >> num;
}catch(...){
break; // I also tried "return 1;", "exit(1);" with no success
}
}while(1);
return 0;
}
请注意,我不是c ++专家。