c++ - 枚举类仅适用于 -std=c++11

标签 c++ c++11 enums

所以我尝试学习 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 支持。

  1. 导航到工具 -> 编译器选项
  2. 设置选项卡
  3. 代码生成选项卡
  4. 语言标准-std更改为C++11

关于c++ - 枚举类仅适用于 -std=c++11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36380729/

相关文章:

c++ - 在 C++ 0x 中打开枚举类

visual-studio - 在 Visual Basic 6 上链接 ENUM

c++ - PlaySound()函数不会播放声音

c++ - 在全局变量的初始化/取消初始化中使用隐式加载的 DLL 中的函数

c++ - 如何确保返回 vector <unique_ptr> 的常量

Java : Convert Object consisting enum to Json Object

java - 如何创建通用枚举转换器?

c++ - 更改 vector 中的值后,make_heap 无法按预期工作?

c++ - 如何按字节数对 C(或 C++)对象进行类型转换

c++ - 通常,解引用指针表达式结果是引用类型吗?