谁能告诉我如何初始化下面的容器? key是固定的,下面两列信息应该根据key访问,并且应该可以在迭代中更新:
谁能告诉我如何访问以下 map 容器中的可变大小列?
map<unsigned int, vector<vector<unsigned int>> > polyMap;
0 0 20
1 30
2 40
. .
face(n) some angles
2 0 20
1 30
. .
face(m) some angles
. . .
. . .
. . .
. . .
(`k vertex) (curesponding faces) (and angles)`
大家好,看来我的问题不完整:事情是这样的,我有顶点编号(即 uniq=key)和围绕该顶点的面以及各自的角度:示例如下所示
你能告诉我是否可以为上述目的制作问题中所示的 map 容器吗?
最佳答案
你可能想要这样的东西:
#include <map>
#include <vector>
#include <assert.h>
using namespace std;
int main()
{
// Declare initialized polyMap
map<unsigned int, vector<vector<unsigned int>> > polyMap
{
{ 11,
{
{ 1,2 }, { 3,4 }
}
},
{ 22,
{
{ 5,6 }, { 7,8 }
}
}
};
// add another element dynamically
polyMap.insert(pair<int, vector<vector<unsigned int>>>(
{ 33,
{
{ 9, 10 },{ 11, 12 }
}
}
));
// check expected outcome for some values
assert(polyMap[11][0][0] == 1);
assert(polyMap[11][0][1] == 2);
assert(polyMap[22][1][1] == 8);
assert(polyMap[33][1][1] == 12);
}
关于c++ - 如何为以下容器赋值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48442718/