【发布时间】:2021-12-31 18:06:13
【问题描述】:
我试图在我的代码中使用开关盒作为用户的一种菜单选择。我有这个枚举列表:
enum menuChoice {ADD = 1, REMOVE = 2, DISPLAY = 3, SEARCH = 4, RESULTS = 5, QUIT = 6};
然后我有这个代码:
menuChoice switchChoice;
Student student;
cout << "1. Add\n" << "2. Remove\n" << "3. Display\n" << "4. Search\n";
cout << "5. Results\n" << "6. Quit" << endl;
for (int i = 0; i < 999; ++i)
{
cout << "Please enter choice:";
cin >> userChoice;
if (userChoice > 6 || userChoice < 1)
{
cout << "Incorrect choice. Please enter again" << endl;
}
else
{
break;
}
}
switchChoice = static_cast<menuChoice>(userChoice);
switch(switchChoice){
case 1:
add_Student(student);
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
default:
}
这是什么导致了这个错误:
error: expected primary-expression before ‘}’ token
我真的为这件事摸不着头脑。这里有什么错误?我如何不实现主要表达式?我知道您不应该将类型传递给开关参数,但这是我要传递的枚举变量。非常感谢您对此提供一些帮助。
【问题讨论】:
标签: c++ enums compiler-errors switch-statement