int main(int argc, char* argv[]) { string input; //接收键盘输入的表达式 Scan sc; Print pr; Calculation cal; queue<string> q; string res; if (argc == 2) { input = argv[1]; q = sc.toStringQueue(input); sc.clearQue(); pr.print(pr.getInfomation(sc.getFlag(), cal.getResult(q))); } else if (argc == 3 && strcmp(argv[1], "-a") == 0) { input = argv[argc - 1]; q = sc.toStringQueue(input); pr.printQue(q); sc.clearQue(); pr.print(pr.getInfomation(sc.getFlag(), cal.getResult(q))); } else if (argc == 4 && strcmp(argv[1], "-f") == 0) { sc.read(argv[2], argv[3]); } return 0; }
int main(int argc,char *argv[]) { using namespace std; u_int op=0; Scan input; calculation cal; Print output; string arg[2]={"-a","-f"},exp; if(argc==2){ exp=argv[1]; double ans=cal.calc( input.toStringQueue( exp ) ); //调用input类的toStringQueue方法,返回一个<string>的队列,将其传入cal的运算函数得到结果 output.print(exp,ans,op,cout); }else if(argc>2&&arg[0]==argv[1]){ op=1; exp=argv[2]; double ans=cal.calc( input.toStringQueue( exp ) ); //调用input类的toStringQueue方法,返回一个<string>的队列,将其传入cal的运算函数得到结果 output.print(exp,ans,op,cout); }else if(argc>3&&arg[1]==argv[1]){ op=2; ifstream in(argv[2]); ofstream out(argv[3]); if(!in||!out){ cout<<"Open File ERROR"<<endl; exit(-1); } int cnt=0; while(!in.eof()){ in>>exp; double anst; anst=cal.calc( input.toStringQueue( exp ) ); //调用input类的toStringQueue方法,返回一个<string>的队列,将其传入cal的运算函数得到结果 output.print(exp,anst,op,out); cnt++; if(cnt%1000)out<<flush; } in.close(); out.close(); }else{