Using Switch with enum in C++

Please note that:

Each switch action is associated with the value of an integral constant
expression (i.e., any combination of character and integer constants
that evaluates to a constant integer value).

From the previous statement we see that it OK to use the enum values inside the switch cases because the enum values are treated as numbers.

So in your case, it is not possible to make the user enter a string input and then you check that input in a switch case. Before using the input with switch case, you should convert the user input (whatever it was) to an integral constant expression so that you can use inside the switch case.
You may also refer to this, I think it is helpful for you.

Leave a Comment