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

王朝c/c++·作者佚名  2006-01-14
窄屏简体版  字體: |||超大  

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

#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);

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有  導航