所以我尝试学习 Enum 类。我从我的书中复制了这段代码:
#include <iostream>
using namespace std;
int main()
{
enum class Color
{
RED,
BLUE
};
Color color = Color::RED;
if (color == Color::RED)
cout << "The color is red!\n";
else if (color == Color::BLUE)
cout << "The color is blue!\n";
return 0;
}
我希望代码打印出“The Color is red!” 但是,我的编译器给出了这个错误:
warning: scoped enums only available with -std=c++11 or -std=gnu+11
和
error:'Color' is not a class or namespace
我目前正在使用 Dev-C++5.11。知道如何解决这个问题吗?
最佳答案
按照说明进行操作 here启用 C++11 支持。
- 导航到工具 -> 编译器选项
- 设置选项卡
- 代码生成选项卡
- 将
语言标准-std
更改为C++11
关于c++ - 枚举类仅适用于 -std=c++11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36380729/