std::数组 我得到了
no match for ‘operator=’ in ‘myarr = {1, 5, 2, 3, 4}’
编译这段代码时出错
#include <iostream>
#include <array>
using namespace std;
int main(int argc, char const *argv[])
{
array<int, 5> myarr;
myarr = {1,5,2,3,4};
for(auto i : myarr)
{
cout << i << endl;
}
return 0;
}
但是当我在同一行时它会编译
array<int, 5> myarr = {1,5,2,3,4};
如何在单独的行上赋值
我需要在类构造函数中赋值,我该怎么做?
class myclass
{
myclass()
{
myarr = {1,2,3,4,5}; /// how to assign it // it gives errors
}
};
最佳答案
您需要两个而不是一对牙套。
myarray = {{1,2,3,4,5}};
关于c++ - std::array c++11 初始值设定项语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9314727/