我想这个转换成switch语句switch语句多字符常量
if (codeSection == 281)
cout << "bigamy";
else if (codeSection == 321 || codeSection == 322)
cout << "selling illegal lottery tickets";
else if (codeSection == 383)
cout << "selling rancid butter";
else if (codeSection == 598)
cout << "wounding a bird in a public cemetery";
else
cout << "some other crime";
// Actual switch statement
switch (codeSection)
{
case '281':
cout << "bigamy" << endl;
break;
case '321':
case '322':
cout << "selling illegal lottery tickets" << endl;
break;
case '383':
cout << "selling rancid butter" << endl;
break;
case '598':
cout << "wounding a bird in a public cemetery";
break;
default:
cout << "some other crime"<< endl;
}
编译器说switch语句多字符常量,并给了我一个黄色的警告,但仍然编译。我的问题是这种情况应该只是字符形式?类似情况下,“2”
你应该知道,编译器**警告**是你应该在劝告下采取的,但不一定会破坏任何东西。事实上(但并非必须),许多警告可以关闭。 **错误**,另一方面,阻止您的代码编译或正确运行。 – CodeMouse92