我想這個轉換成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