关于后缀表达式计算的问题求助
我在练习借助栈计算后缀表达式时遇到了一些问题,输入表达式后按enter就报段错误,请大家帮忙看看代码有哪些问题。int main()
{
stack<double> st;
while(true)
{
char c = cin.peek();
if(c == '\n')
{
break;
}
if(c >= '0' && c <= '9')
{
//读入数字
double num;
cin >> num;
st.push(num);
}
else
{
//读入运算符
cin >> c;
EvalMethod method = select(c);
double num1, num2;
num1 = st.top();
st.pop();
num2 = st.top();
st.pop();
st.push(calc(num1, num2, method));
}
}
int result = st.top();
st.pop();
if(st.empty())
{
cout << result << endl;
}
else
{
cout << "Error" << endl;
}
return 0;
} 还有就是关于cin操作的一些细节不是很明了
页:
[1]