+ 3

Why am I getting error when writing switch statement with string

switch statement https://code.sololearn.com/cLuNJ9rG4r5F/?ref=app

29th Apr 2019, 11:38 AM
Ghet Rich
Ghet Rich - avatar
6 odpowiedzi
+ 2
if I get what you are saying right, do you mean we don't use string in switch statement
29th Apr 2019, 12:08 PM
Ghet Rich
Ghet Rich - avatar
+ 2
if I get what you are saying right, do you mean we don't use string in switch statement
29th Apr 2019, 12:08 PM
Ghet Rich
Ghet Rich - avatar
+ 2
Okay thanks
29th Apr 2019, 1:12 PM
Ghet Rich
Ghet Rich - avatar
+ 1
taken from https://en.cppreference.com/w/cpp/language/switch condition-any expression of integral or enumeration type, or of a class type contextually implicitly convertible to an integral or enumeration type, or a declaration of a single non-array variable of such type with a brace-or-equals initializer. soo.. you cant have string in there, its still possible to use char
29th Apr 2019, 11:51 AM
Taste
Taste - avatar
+ 1
yes
29th Apr 2019, 12:10 PM
Taste
Taste - avatar
0
"case" must be followed by a constant integer and must be ended by a "break" (which you forgot). But nothing stop you from writing if (name=="george") cout<<"hi george"<<endl; else if (name=="sam") cout<<"hi sam"<<endl; else cout<<"name not found"<<endl;
29th Apr 2019, 12:41 PM
Bilbo Baggins
Bilbo Baggins - avatar