+ 2
Can you use switch statements with strings? If so a do I achieve that?
2 Answers
+ 10
Switch statements only work with integers and characters for case. Still, there are ways around this. For example, you can use the first character of the string to denote what should be done. E.g.
string str = "test";
switch (str[0])
{
case 'a' : //something
case 'g' : //something
case 't' : //something
}
0
You can't do this leastways not in C++.