+ 1
can we use switch with char and string
4 Answers
+ 3
Java: Yes, you can use char and String. Switch statement with String was implemented in Java7.
+ 1
i was asking for c++ but thanks for your answer. if you know about c++ pls help me with it.
+ 1
You can't use a string with a switch statement in c++, but you can use a char. A string in c++ is basically a char array and attempting to use a string would be like trying to switch on an array. You could get a char from a string and switch on that just fine though.
Really AFAIK you can only switch on an integer type (int), but since char is basically an int it works also.
+ 1
thanku very much