本文整理汇总了C++中Commands::commandP方法的典型用法代码示例。如果您正苦于以下问题:C++ Commands::commandP方法的具体用法?C++ Commands::commandP怎么用?C++ Commands::commandP使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Commands
的用法示例。
在下文中一共展示了Commands::commandP方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//to be inserted in main
int main() {
string commLine;
Commands * c = new Commands();
while(1) //wamt jos tp lee[ going because exit will end it here or in functions
{
prompt(); //prints [USERNAME]@[HOSTNAME]$
getline(cin, commLine);
size_t foundTest = commLine.find("test"); //this will check "test" in the string
size_t foundFirstBracket = commLine.find("["); //this will check "[" in the string
size_t foundSecBracket = commLine.find("]"); // this will check "]" in the string
// check if the string has "test" or "[]" in the string
if(foundTest != string::npos || (foundFirstBracket != string::npos && foundSecBracket != string:: npos))
{
c->testP(commLine);
}
else if(commLine == "exit") //EXIT program if user types "exit"
{
exit(0);
}
else
{
c->commandP(commLine);
}
}
// Commands * c = new Commands();
// string commLine;
// vector <string> com;
// vector <bool> returnv;
// while(1)
// {
// prompt();
// getline(cin, commLine);
// while(commLine != "") //while not empty string
// {
// int endP = commLine.find(")");
// if (commLine.find(")") != string::npos)
// {
// if (endP > commLine.find("||") && endP > commLine.find("&&") && endP > commLine.find(";"))
// {
// if (commLine.find("(") != string::npos)
// {
// int beginP = commLine.find("(");
// com.push_back(commLine.substr(beginP, endP)); //so that it gets rid of the parentheses
// commLine.erase(beginP, endP); //erase that second from the string
// }
// else
// {
// perror("Invalid command.");
// }
// }
// else
// {
// int beginP = commLine.find("(");
// if (beginP != string::npos)
// {
// int findAND = commLine.find("&");
// int findOR = commLine.find("|");
// int findSEMI = commLine.find(";");
// if (findAND != string::npos && findAND - 3 <= 0)
// {
// com.push_back("&&");
// commLine.erase(0, 2);
// }
// else if (findOR != string::npos && findOR - 3 <= 0)
// {
// com.push_back("||");
// commLine.erase(0, 2);
// }
// else if (findSEMI != string::npos && findSEMI - 3 <= 0)
// {
// com.push_back(";");
// commLine.erase(0, 2);
// }
// com.push_back(commLine.substr(0, beginP - 1));
// commLine.erase(0, beginP - 1);
// }
// else
// {
// perror("Invalid command");
// }
// }
// }
// else
// {
// size_t foundTest = commLine.find("test"); //this will check "test" in the string
// size_t foundFirstBracket = commLine.find("["); //this will check "[" in the string
// size_t foundSecBracket = commLine.find("]"); // this will check "]" in the string
// // check if the string has "test" or "[]" in the string
// if(foundTest != string::npos || (foundFirstBracket != string::npos && foundSecBracket != string:: npos))
// {
// c->testP(commLine);
// commLine.erase(0, commLine.size() - 1);
// }
// else if(commLine == "exit") //EXIT program if user types "exit"
//.........这里部分代码省略.........