+ 4
Can you put a string oporation into a switch statement?
I'm working on a switch statement that would require a string operation input. Is this possible, and if so, how?
8 Antworten
+ 12
you could use enum?
+ 11
It's not possible to use strings as case values because of how C++ supports strings.
However, any switch can be replaced with a chain of if/else if/else, which will work the same way.
+ 3
While I definitely recommend avoiding strings due to a whole plethora of reasons (case, encoding, etc), you can technically create a constexpr hash function and use that in your switch statement. Be wary of collisions if you take that route.
+ 2
Thank you, just trying to give an old If/Then code an upgrade
0
Yes, in PHO and Javascript
0
PHP
0
yes. why not?
https://www.sololearn.com/discuss/1293699/?ref=app