在 2D 向量中使用第三个 [ ] 有什么意义?

What's pupose for using the third [ ] in a 2D vector?

本文关键字:三个 什么 向量 2D      更新时间:2023-10-16
vector<char>  T[3][4];  //this is a 2d vector table right?
vector<char> v;
for (int x = 0; x <3; x++)
{
for (int y = 0; y <4; y++)
{
for (int z = 0; z <T[x][y].size(); z++) //T.[x][y].size() is the size of?
{
v.push_back(T[x][y][z]);  //Why we need use [z] for copying values in T to v?
}                           //T is a 2D vector, it should only have two []'s, right?
}
}

大家好。这是我的导师写的一段C++代码,但我真的很困惑。请看这段代码中的评论部分。提前谢谢!

vector<char> T[3][4]; //this is a 2d vector table right?

不,它是char的1D矢量的2D阵列。

因此,总的来说,它是3D的,它匹配/支持三重[]结构。

for (int z = 0; z <T[x][y].size(); z++) //T.[x][y].size() is the size of?

在2D阵列的位置x、y处找到的矢量。

v.push_back(T[x][y][z]); //Why we need use [z] for copying values in T to v?

被推送到v的是在2D阵列T的位置x,y处找到的向量中的索引z的内容。