[英]Accessing elements in a 2d Array of Vectors
I have a 2d Array of Vectors declared as 我有一个向量的二维数组声明为
Vector<int> v1[10][11];
and I want to accessing the elements inside the array. 我想访问数组中的元素。 Would I treat the 2d array of vectors as a 3d array and access elements like this: 我会将向量的2d数组视为3d数组,并像这样访问元素:
v1[9][10][0];
to access the first element of the last member of the array? 访问数组的最后一个成员的第一个元素?
std::vector allows the [] operator, but I'm pretty sure your [9][10][0] is going to be out of bounds - you don't have anything there. std :: vector允许使用[]运算符,但是我很确定您的[9] [10] [0]将超出范围-您那里什么都没有。 Assuming that you're opting for an array something like 假设您选择的数组类似
[0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19
...
100 101 102 103 104 105 106 107 108 109]
then the last element is going to be v1[9][10], corresponding to 109 in the picture. 那么最后一个元素将是v1 [9] [10],对应于图片中的109。
If you want each element to be an array, I think you'll need 如果您希望每个元素都是一个数组,我认为您需要
std::vector<int[sizeofarray]> v1[10][11];
//or just vector<int[size]> v1[10][11]; if using namespace std;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.