using a "f" as a switch input

I want to make a characters x and y coordinates change when the user types "u" "d" "l" or "r" (up down left or right) so I used:
1
2
3
4
5
6
7
char input;
cin << input;
switch (input) {
case "u" :
playerx ++
break;
}


that was only a shortened version of the code, but it gave me the error message :

"error: case label does not reduce to an integer constant"

how can I switch based on characters? I don't want to use if structures, to keep my code clean...

Last edited on
C and C++ distinguish character literals

'a'

from string literals

"a"

You cannot switch on a string --only on things that reduce to simple ordinal types (integers, enums, etc).

Hope this helps.
Thank you for your fast response, it works :D
Topic archived. No new replies allowed.