switch is only for integral types , if you want to branch depending on a string you need to use if/else .
Read moreHow do I convert an enum to a string in C++?
Use Custom Defined Function to Convert an Enum to a String in C++ Alternatively, we can define our own function, which takes an integer as a parameter and returns a string value. The string variable is initialized with a const char* value from enum_str array inside the function.
Read moreCan enum be string C++?
Here we will see how to map some enum type data to a string in C++. There is no such direct function to do so. But we can create our own function to convert enum to string . We shall create a function that takes an enum value as the argument, and we manually return the enum names as a string from that function.
Read moreCan you switch on an enum C++?
In C++, enums are permitted to have values other than the explicit enumerators. … After execution falls through the switch statement, it reaches the end of the function without returning a value, which is undefined behavior for a function with a non-void return type.
Read moreCan we use string in switch case in C?
No you can’t . The case labels of a switch need to be compile time evaluable constant expressions with an integral type.
Read moreWhat data types can be used in a switch statement C?
1) The expression used in switch must be integral type ( int, char and enum) . Any other type of expression is not allowed.
Read moreCan you use a switch statement with a string C++?
There are a number of requirements to make a function or an expression constexpr, but we can still use that to make switch/case work on strings (or const char *). The switch/case statement itself will still require an integral operand, so we must transform a string into an integral value.
Read more