用C++编写的模仿dos命令响应代码

//一下代码包含有程序的一些自定义的标识符,也许在本文中使用。由于篇幅的原因其定义不在本文中说明,请原谅

#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <utility>
using namespace std;

/*-------------Function @ StatisticComDispatch @ discription <----------------*
*@name: void StatisticComDispatch();                                          *
*@parameter:                                                                  *
*@purpose: It is used for despatching commands                                *
*@return value: void                                                          *
*-----------------------------------------------------------------------------*/
void StatisticComDispatch() {
 //功能函数入表
 funcMap.insert(make_pair(string("AmountShow"), &AmountShow));
 funcMap.insert(make_pair(string("RelativeShow"), &RelativeShow));
 funcMap.insert(make_pair(string("new"), &NewStatistic));
 funcMap.insert(make_pair(string("continue"), &Continue));
 funcMap.insert(make_pair(string("reInput"), &ReInput));
 funcMap.insert(make_pair(string("import"), &ReadFromFile));
 funcMap.insert(make_pair(string("export"), &WriteToFile));
 funcMap.insert(make_pair(string("makeFile"), &WrFmToFile));
 funcMap.insert(make_pair(string("showData"), &ShowData));
 funcMap.insert(make_pair(string("help"), &ShowHelp));
 funcMap.insert(make_pair(string("quit"), &Quit));

 
 //----------------------------------------------------//
 
 stringEx strCI, strData;
 
 cout << "请输入你的命令:(输入help获得帮助) " << endl;
 
 char command[COMMAND_MAX_LENGTH];
 stringEx strCommand;
 stringEx subCommand;
 
 
 //===================================================//
 //              以下是处理命令的代码                 //
 //===================================================// 
 
 do {
  cin >> strCommand;
  cin.getline(command, COMMAND_MAX_LENGTH);
  
  if (!cin) {  //命令输入错误
   clog << "命令输入错误!  请重新输入。" << endl;
   continue ;
  }
  //**********************************************//
  //-----> 如果输入正常则执行下面语句 <-----------//
  //**********************************************//
  
  //把命令行保存到字符串对象中
  strCommand.append(command,0,COMMAND_MAX_LENGTH);
  
  
  
  //保存选项
  int selection = 0;
  
  try {
   //如果整个命令行不是少于三步分(用两个空格分开)的话,就提示命令输入错误
   if (strCommand.GetSubStringNum(DATA_DIVIDER) > 3) {
    throw errMsg[ERR_MSG_TOO_MANY_PARAMETERS];
   }
   //逐个判断命令
   subCommand = strCommand.GetSubString(1, DATA_DIVIDER);
   
   if (funcMap.find(subCommand) != funcMap.end()) {
    ShowDivideLine(true);
    
    (*funcMap[subCommand])(strCI, strData, strCommand);
    
    ShowDivideLine(false);
   }
   else {
    throw errMsg[ERR_MSG_ILLEGAL_STATEMENT];
   }
  }
  catch (stringEx::InvtStringException err) {
   clog << err.GetErrMsg() << endl;
   
   ShowDivideLine(false);
   
   continue;
  }
  catch (const char *errMsg) {
   clog << errMsg << endl;
   
   ShowDivideLine(false);
   
   continue;
  }
  catch (...) {
   clog << errMsg[ERR_MSG_UNKNOWN_ERROR] << endl;
   getch();
   
   abort();
  }
 }while(true);
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值