简体   繁体   English

C++ 标准模板库简单代码在 macos mojave 中的 vs 代码中给出错误

[英]C++ Standard Template Library simple code giving error in vs code in macos mojave

I am working in STL in c++ in the vs code editor and i have declared an array as given in the code below...我在 vs 代码编辑器中的 c++ 中的 STL 中工作,我已经声明了一个数组,如下面的代码中给出的......

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    vector<int> arr={11,2,13};
    for(int i=0;i<3;++i)
    cout<<arr[i]<<" ";
    return 0;
}

I am getting the error that non-aggregate type vector cannot be initialized with an initialiser list.我收到无法使用初始化列表初始化非聚合类型向量的错误。 When i compiled the code in Clion ide, it works fine.当我在 Clion ide 中编译代码时,它工作正常。 So what is the problem in vs code?那么vs代码有什么问题呢?

It seems the compiler does not support c++11.看来编译器不支持 c++11。

you can use -std=c++11 and try again.您可以使用-std=c++11再试一次。

eg.例如。 g++ -std=c++11 -c example.cpp

And also can get more info form this why am I getting “non-aggregate cannot be initialized with initializer list并且还可以获得更多信息, 为什么我会得到“非聚合不能用初始化列表初始化”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM