“案例"之前的预期不合格ID [英] Expected Unqualified-id before 'case'
问题描述
声明数组时出现错误.为什么会发生这种情况,我该如何解决?我似乎无法在不引发此错误的情况下声明数组.在此之前,我曾尝试使用vector<>.我正在寻找创建一个字符串数组.我已经在Google上搜索了此错误,并且对于我看到的几乎每个人,通过切换代码即[[] array而不是" array [],这都是语法错误.在这里,我以正确的顺序放置了数组语法,但是仍然出现此错误.谢谢
I get the error when I declare the array. Why does this happen and how do I fix it? I can't seem to declare the array without throwing this error. I tried using vector<> previously before this. I'm looking to create an array of strings. I've searched this error on google and for almost everyone I saw, it was a syntax error by switching around the code i.e "[]array" instead of "array[]". Here, I've put the array syntax in the correct order, but I still get this error. Thanks
int main()
{
const string case[3]; //<- Error right here before 'case'
int selection; //choice to open skin
srand( time(0));
int skinChance; //The number that determines the skin quality
while(true)
{
cout << "Open Case \n";
cin >> selection;
if(selection == 1)
{
skinChance = rand()%10;
if (skinChance <= 5)
{
//Blue Skin
}
else if (skinChance >= 6 && skinChance <= 9)
{
//Purple/Pink Skin
}
else if (skinChance == 10)
{
//Red Skin
}
}
else
{
cout << "Not valid\n";
}
}
}
推荐答案
case
在C ++中是受保护的关键字,因为它是switch-case语句所必需的.您不能将其用作变量名.
case
is a protected keyword in C++, as it is neccessary for the switch-case statements. You can't use it as a variable name.
这篇关于“案例"之前的预期不合格ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!