#856: 一点疑问


skies457 (Skywalker)


请问这段程序在那里出错,为什么第6行WA???我自己调试没有发现问题啊衰死了~~

#include <iostream>
#include <cstdlib>
#include <cctype>
using namespace std;
int main()
{
    string str;
    unsigned int i,j,sp;
    long int stack[65535];
    while(getline(cin,str)){
        sp=0;
        for(i=0;i<str.length();i++){
            if(str.c_str()[i]=='+') {
                stack[sp-2]=stack[sp-1]+stack[sp-2];
                sp--;
            }else if(str.c_str()[i]=='-'){
                stack[sp-2]=stack[sp-2]-stack[sp-1];
                sp--;
            }else if(str.c_str()[i]=='*'){
                stack[sp-2]=stack[sp-2]*stack[sp-1];
                sp--;
            }else if(str.c_str()[i]=='/'){
                stack[sp-2]=stack[sp-2]/stack[sp-1];
                sp--;
            }else if(isdigit(str.c_str()[i])){
                stack[sp++] = atoi(str.substr(i,str.length()-1).c_str());
                for(j=i;j<str.length();j++){
                    if(str.c_str()[j]<'0' || str.c_str()[j]>'9'){
                        break;
                    }
                }
                i=j-1;
            }
        }
        cout<<stack[0]<<endl;
    }
    return 0;
}