加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 编译器错误:“无法使用初始化列表初始化非聚合.”

发布时间:2020-12-16 07:16:01 所属栏目:百科 来源:网络整理
导读:当尝试在C中创建一个简单的向量时,我收到以下错误: Non-aggregates cannot be initialized with initializer list. 我正在使用的代码是: #include iostream#include string#include vectorusing namespace std;int main(int argc,char *argv[]){ vector in
当尝试在C中创建一个简单的向量时,我收到以下错误:

Non-aggregates cannot be initialized with initializer list.

我正在使用的代码是:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(int argc,char *argv[])
{
    vector <int> theVector = {1,2,3,4,5};
    cout << theVector[0];
}

我试图把:

CONFIG += c++11

进入我的.pro文件,保存并重建它.但是,我仍然得到同样的错误.我正在使用我认为是Qt 5.5的内容,这就是当我按下关于它对你有什么意义时会发生什么:Qt’s About.

任何帮助表示赞赏.

解决方法

以下行:

vector <int> theVector = {1,5};

不会编译前C 11.

但是,你可以这样做:

static const int arr[] = {1,5};
vector<int> theVector (arr,arr + sizeof(arr) / sizeof(arr[0]) );

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读