f0512.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:

C#编程

开发平台:

Visual C++

  1. //=====================================
  2. // f0512.cpp
  3. // 命令解析
  4. //=====================================
  5. #include<iostream>
  6. #include<sstream>
  7. using namespace std;
  8. //-------------------------------------
  9. int main(int argc, char** argv){
  10.   if(argc!=2){
  11.     cout<<"usage: f0512 commandn";
  12.     return 1;
  13.   }
  14.   string s(argv[1]);
  15.   istringstream sin(s);
  16.   int a,b;  char c;
  17.   sin>>a>>c>>b;
  18.   switch(c){
  19.     case'-': b=-b;
  20.     case'+': cout<<a+b; break;
  21.     case'*': cout<<a*b; break;
  22.     case'/': cout<<a/b; break;
  23.     default: cout<<"error";
  24.   }
  25. }//====================================
  26.