简体   繁体   中英

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...

#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. So what is the problem in vs code?

It seems the compiler does not support c++11.

you can use -std=c++11 and try again.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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