I'm writing this code that takes in a char userinput
and uses the switch statement do execute the respective command. However because C++
switch statements can only read ints and enums, I'm not sure how to incorporate this. The user input must be a char. any ideas? I know charInput
>> enumInput
doesn't work but I'm not sure what to do.
int main(int argc, char** argv) {
enum charCommand { i, d, s, n, r, a, m, t, p, l, q };
charCommand enumInput;
while (mainLoop) {
cout << "enter valid input" endl;
char charInput;
printf("Enter a command: ");
cin >> charInput;
charInput >> enumInput;
switch (charInput) {
case i: {
printf("This is case i");
exit(0);
} //case i
default: {
cout << "invalid command, try again!\n";
}
}
};
}