我想声明一个结构,比如大小为 n=10,在该结构的每个 i 位点中都有一个 vector 。结构位点中的载体具有不同的大小。
在matlab中可以使用struct获取。它是如何在 C++ 中完成的?
最佳答案
我认为您正在寻找的是 vector 的数组或 vector 。
例如:
#include <array>
#include <vector>
#include <iostream>
int main ()
{
std::array<std::vector<int>, 10> Vectors;
for (auto &i : Vectors) //Loop through all 10 vectors in Vectors
{
for (int j=0; j<5; j++) //Push 1, 2, 3, 4, and 5 into each vector
{
i.push_back(j);
}
}
return 0;
}
关于c++ - 包含不同大小的 vector 的结构,cpp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33439212/