Is there a better way to parse words in a string to pass as "commands for the console"? I'm making a customized CLI, and have a whole bunch of if statements like so:
if (line[x] == 'a') {
}
if (line[x] == 'b') {
} // BELOW IS WHAT I WANT TO ELIMINATE: PARSING CHAR BY CHAR
if (line[x] == 'c') {
if (line[x+1] == 'o') {
if (line[x+2] == 'l') {
if (line[x+3] == 'o') {
if (line[x+4] == 'r') {
SetColor(10);
}
}
}
}
}
/*
if (line[x] == 'd') {
}
if (line[x] == 'e') {
}
if (line[x] == 'f') {
}
if (line[x] == 'g') {
}
if (line[x] == 'h') {
}
if (line[x] == 'i') {
}
if (line[x] == 'j') {
}
if (line[x] == 'k') {
}
if (line[x] == 'l') {
}
if (line[x] == 'm') {
}
if (line[x] == 'n') {
}
if (line[x] == 'o') {
}
if (line[x] == 'p') {
}
if (line[x] == 'q') {
}
if (line[x] == 'r') {
}
if (line[x] == 's') {
}
if (line[x] == 't') {
}
if (line[x] == 'u') {
}
if (line[x] == 'v') {
}
if (line[x] == 'w') {
}
if (line[x] == 'x') {
}
if (line[x] == 'y') {
}
if (line[x] == 'z') {
} */
Is there any way to parse a command (below) to make the console set the color to lime green? (<-- I know how to do that, but how do I parse the command with switches/parameters?)
well for one you could input a string by using getline(cin, stringname); and that would get rid of the having to if 'c' if 'o' ect..for color but the color code eg 'l'g' might be a bit more difficult for the switch since switches are in this formart switch(char), switch(int) and not switch(string) but you could convert the letters to numbers then change color based on that.
and then you could do soemthing like