-8

编译错误时出错:break 语句不在循环内或 switch case 标签'不在 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;
4

1 回答 1

2

案例语法示例

switch (variable)
{
   case 1:
      //Do stuff
      break;
   case 2:
      //Do stuff
      break;
   default:
      //Do stuff
      break;
}

请记住,通过使用 switch 语句,您只能处理整数变量。并且您需要指定哪些变量case语句引用 usingswitch语句。如果您坚持要测试一个char*变量,那么行为将与您的预期不同,因为您将只比较指针,而不是char*数组的内容。

在您的情况下,您最好使用if, else if

于 2013-05-13T07:29:10.610 回答