+ 3
Why am I getting error when writing switch statement with string
switch statement https://code.sololearn.com/cLuNJ9rG4r5F/?ref=app
6 Antworten
+ 2
if I get what you are saying right, do you mean we don't use string in switch statement
+ 2
if I get what you are saying right, do you mean we don't use string in switch statement
+ 2
Okay thanks
+ 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
+ 1
yes
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;