C ++标准模板库简单代码在macos mojave中的vs代码中给出错误
C++ Standard Template Library simple code giving error in vs code in macos mojave
我在 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;
}
我收到无法使用初始化列表初始化非聚合类型向量的错误。
当我在 Clion ide 中编译代码时,它工作正常。
那么vs code的问题是什么?
好像编译器不支持c++11
您可以使用 -std=c++11
再试一次。
例如。 g++ -std=c++11 -c example.cpp
并且还可以从这个 why am I getting “non-aggregate cannot be initialized with initializer list
中获取更多信息
我在 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;
}
我收到无法使用初始化列表初始化非聚合类型向量的错误。 当我在 Clion ide 中编译代码时,它工作正常。 那么vs code的问题是什么?
好像编译器不支持c++11
您可以使用 -std=c++11
再试一次。
例如。 g++ -std=c++11 -c example.cpp
并且还可以从这个 why am I getting “non-aggregate cannot be initialized with initializer list
中获取更多信息