警告:扩展的初始化程序列表仅在-std = c ++ 11或-std = gnu ++ 11中可用[默认启用]

问题描述

我不知道为什么我遇到错误

“警告:扩展的初始化程序列表仅在-std = c ++ 11或-std = gnu ++ 11 [认启用]下可用”

我有.h和.cpp文件

在.h文件中,我已经声明了变量名称

 class file
 {
   private:
     string* arr;
   public:
     void list();
 }

在.cpp文件

void file::list()
{
  arr = new string[2]{"1","2"}; 
}

解决方法

我不知道为什么我遇到错误

warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]

之所以收到警告,是因为在上下文中使用了初始化列表,直到C ++ 11才允许使用它,并且您没有使用C ++ 11或更高版本。因此,程序格式错误,需要编译器向您显示一条消息。