+ 1
How to Create a replacement for the switch statement in C++ that also works for strings
I need a solution
5 Answers
+ 7
Switch also works for characters, and strings are character arrays. There's probably a way to make things work, but it will depend on the case of your program and the strings you want to evaluate.
+ 5
Maybe you can try marking each string with a unique number, and then check for the number using switch.
That number may be :
0) Sum of All ASCII Codes of the characters in the string.
1) Sum of First Char's ASCII Code + Length of the string.
etc,etc...
+ 3
convert the string to a number maybe?
+ 3
@Hatsy Rei Yes but characters are just numbers. It wouldnt make sense to go through the trouble instead of just using a simple if statement
+ 2
You have to use if statements. Switches are only for numbers, not entire strings