因此,我试图学习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;
}


我希望代码可以打印出“颜色为红色!”。
但是,我的编译器给出此错误:

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支持。


导航到工具->编译器选项
设置标签
代码生成选项卡
Language standard -std更改为C ++ 11

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

10-12 00:34
查看更多