我正在尝试编写一个用于评估postfix-expression的程序 代码:
#include <iostream>
#include <cstring>
#include <stack>
#include <ostream>
using namespace std;
int main(int argc,char *argv[]){
char *a=argv[1];
int n=strlen(a);
stack<int>s;
for (int i=0;i<n;i++)
{
if (a[i]=='+')
s.push(s.pop()+s.pop());
if (a[i]=='*')
s.push(s.pop() * s.pop());
if ((a[i]>='0') && (a[i]<='9'))
s.push(0);
while ((a[i]>='0') && (a[i]<='9'))
s.push(10*s.pop()+(a[i++]-'0'));
}
cout<<s.pop()<<endl;
return 0;
}
但是错误说明了
1>c:\users\david\documents\visual studio 2010\projects\compilers\compilers.cpp(16): error C2296: '*' : illegal, left operand has type 'void'
1>c:\users\david\documents\visual studio 2010\projects\compilers\compilers.cpp(16): error C2297: '*' : illegal, right operand has type 'void'
1>c:\users\david\documents\visual studio 2010\projects\compilers\compilers.cpp(21): error C2297: '*' : illegal, right operand has type 'void'
1>c:\users\david\documents\visual studio 2010\projects\compilers\compilers.cpp(25): error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'void' (or there is no acceptable conversion)
我认为我有一个类型字符串或类型char的堆栈,但都不起作用。我该如何解决这个问题?