#include<bits/stdc++.h>
using namespace std;
int main(){
string expr; //运算表达式
int a, b, result;
char op; //运算符
// cin>>expr;
getline(cin, expr);
//【解析】字符串=> a op b ————>使用istringstream类(input)
istringstream iss(expr);
if(!(iss>>a>>op>>b)){ //解析失败——>报错信息,终止
cerr<<"输入运算表达式格式不正确!"<<endl;
return 1;
}
//解析成功:
/* op的可能性: + - * / ——————> switch() case 某值 default:
同时, / 要检验分母合法性 */
try{
switch(op){
case '+':
result = a+b;
break;
case '-':
result = a-b;
break;
case '*':
case 'X':
case 'x':
result = a*b;
break;
case '/':
if(b==0){
throw "除数不能为零!"; //【抛出】异常
}
result = a/b;
break;
defalt:
cerr<<"不支持的运算符!"<<endl;
return 1;
}
}catch(const char* e){ //【捕获】异常
cout<<"捕获异常:"<<e<<endl;
}
cout<<"result = "<<result<<endl;
return 0;
}