//=================================================== //mianArg.cpp 使用mian函数的参数 f0512.cpp //by leo //6.02.2011 //=================================================== #include<iostream> #include<fstream> #include<sstream> using namespace std; //--------------------------------------------------- int main(int argc, char** argv) { //for(int a, int b; cin>>a>>b; cout<<a+b<<endl); /* //--------输入输出文件作为main参数--------------- for(int i=0; i<argc; i++) cout<<argv[i]<<endl; if(argc !=3) cout<<"usage: redirect infile outfile"<<endl; else { ifstream in(argv[1]); ofstream out(argv[2]); if(in && out) out<<in.rdbuf(); } */ //-----------命令解析-------------------------- string s(argv[1]); istringstream sin(s); int a, b; char c; sin>>a>>c>>b; switch(c) { case'-': cout<<a-b<<endl; break; case'+': cout<<a+b<<endl; break; case'*': cout<<a*b<<endl; break; default: cout<<"error!!"<<endl; } return 0; } //===================================================