+ 6

Why strings can't be used in switch case in C++. Please answer me.

29th Jan 2018, 5:14 AM
Manu Ojha
Manu Ojha - avatar
3 Answers
+ 5
the tone of this question sounds like we are the language specification committee 😅😅😅, and we should add it in the upcoming draft
29th Jan 2018, 8:52 AM
Morpheus
Morpheus - avatar
+ 1
A string in C/C++ is an array. The raw value isn't the string itself but rather a pointer to the data.
29th Jan 2018, 5:42 AM
Ariphaos
Ariphaos - avatar
0
The switch case only works with integers or things that evaluate as integers (like enums or macros).
29th Jan 2018, 5:34 AM
Vlad Serbu
Vlad Serbu - avatar