这是我为练习而编写的代码。当我编译它时,它不允许编译 cin >> 选择。它显示“错误 2 错误 C2088: '>>' : 对类非法”和“错误 1 错误 C2371: '选择': 重新定义;不同的基本类型” 我可以就如何解决这个问题获得一些建议吗?非常感激!
#include <iostream>
using namespace std;
int main()
{
cout << "Difficulty levels\n\n";
cout << "Easy - 0\n";
cout << "Normal - 1\n";
cout << "Hard - 2\n";
enum options { Easy, Normal, Hard, Undecided };
options choice = Undecided;
cout << "Your choice: ";
int choice;
cin >> choice;
switch (choice)
{
case 0:
cout << "You picked Easy.\n";
break;
case 1:
cout << "You picked Normal. \n";
break;
case 2:
cout << "You picked Hard. \n";
break;
default:
cout << "You made an illegal choice.\n";
}
return 0;
}