0

Can the expression evaluated by switch be a string?

It gave me an error when I tried it.

30th Jun 2016, 6:32 PM
Christian Roos
Christian Roos - avatar
6 Respostas
0
You can switch only integers. So you can create special key for you String value and switch it by keys.
30th Jun 2016, 6:52 PM
Dmitry Pudov
Dmitry Pudov - avatar
0
Using strings with switch statements is illegal in C++, the reason being strings aren't necessarily supported as a type, but more of an array of characters, and the language doesn't quite understand that. With certain other languages though (such as C#) strings CAN be implemented into switch statements.
30th Jun 2016, 6:54 PM
Micah Chaffin
Micah Chaffin - avatar
0
Thanks.
30th Jun 2016, 6:55 PM
Christian Roos
Christian Roos - avatar
0
you can switch integer and char.
30th Jun 2016, 11:21 PM
lam trinh
lam trinh - avatar
0
it is illegal in c c++ java but legal in php
1st Jul 2016, 6:21 PM
Midhun Mathew
0
not at all
13th Jul 2016, 6:22 PM
Bikram Keshari Maharana
Bikram Keshari Maharana - avatar