编译错误时出错: break语句不在循环或开关内 案例标签'不在switch语句
中我无法附上整个代码,因为如果你坚持要看到整件事告诉我并且我会上传一些内容,那就太麻烦了。
void S9xSetupDefaultKeymap()
{
S9xUnmapAllControls();
// Build key map
s9xcommand_t cmd;
// Player 1
S9xMapButton( 65, cmd = S9xGetCommandT("Joypad1 Left"), false ); // A
S9xMapButton( 68, cmd = S9xGetCommandT("Joypad1 Right"), false ); // D
S9xMapButton( 87, cmd = S9xGetCommandT("Joypad1 Up"), false ); // W
S9xMapButton( 83, cmd = S9xGetCommandT("Joypad1 Down"), false ); // S
S9xMapButton( 79, cmd = S9xGetCommandT("Joypad1 X"), false ); // O
S9xMapButton( 80, cmd = S9xGetCommandT("Joypad1 Y"), false ); // P
S9xMapButton( 75, cmd = S9xGetCommandT("Joypad1 A"), false ); // K
S9xMapButton( 76, cmd = S9xGetCommandT("Joypad1 B"), false ); // L
S9xMapButton( 88, cmd = S9xGetCommandT("Joypad1 L"), false ); // X
S9xMapButton( 77, cmd = S9xGetCommandT("Joypad1 R"), false ); // M
S9xMapButton( 13, cmd = S9xGetCommandT("Joypad1 Start"), false ); // Enter
S9xMapButton( 16, cmd = S9xGetCommandT("Joypad1 Select"), false ); // Shift
// Player 2
S9xMapButton( 70, cmd = S9xGetCommandT("Joypad2 Left"), false ); // F
S9xMapButton( 72, cmd = S9xGetCommandT("Joypad2 Right"), false ); // H
S9xMapButton( 84, cmd = S9xGetCommandT("Joypad2 Up"), false ); // T
S9xMapButton( 71, cmd = S9xGetCommandT("Joypad2 Down"), false ); // G
S9xMapButton( 67, cmd = S9xGetCommandT("Joypad2 X"), false ); // C
S9xMapButton( 86, cmd = S9xGetCommandT("Joypad2 Y"), false ); // V
S9xMapButton( 66, cmd = S9xGetCommandT("Joypad2 A"), false ); // B
S9xMapButton( 78, cmd = S9xGetCommandT("Joypad2 B"), false ); // N
S9xMapButton( 89, cmd = S9xGetCommandT("Joypad2 L"), false ); // Y
S9xMapButton( 85, cmd = S9xGetCommandT("Joypad2 R"), false ); // U
S9xMapButton( 81, cmd = S9xGetCommandT("Joypad2 Start"), false ); // Q
S9xMapButton( 69, cmd = S9xGetCommandT("Joypad2 Select"), false ); // E
case "joypad1 down":
break;
case "joypad1 x":
break;
case "joypad1 y":
break;
case "joypad1 a":
break;
case "joypad1 b":
break;
case "joypad1 l":
break;
case "joypad1 r":
break;
case "joypad1 start":
break;
case "joypad1 select"
break;
// player 2
case "joypad2 left":
break;
case "joypad2 right":
break;
case "joypad2 up":
break;
case "joypad2 down":
break;
case "joypad2 x":
break;
case "joypad2 y":
break;
case "joypad2 a":
break;
case "joypad2 b":
break;
case "joypad2 l":
break;
case "joypad2 r":
break;
case "joypad2 start":
break;
case "joypad2 select":
break;
答案 0 :(得分:2)
案例
的示例语法switch (variable)
{
case 1:
//Do stuff
break;
case 2:
//Do stuff
break;
default:
//Do stuff
break;
}
请记住,通过使用switch语句,您只能处理整数变量。您需要指定哪个变量case
语句引用使用switch
语句。如果你坚持要测试char*
变量,那么行为将与你期望的不同,因为你只是比较指针,而不是char*
数组的内容。
在您的情况下,您最好使用if
,else if
。