地图向量中的最后一对地图

Last pair of map in vector of maps

vector<multimap<string, int> > allCount;

我想从地图向量中获取最后一对地图,但我不知道如何做。

int x = 0;
for(iter = patternBase.begin(); iter != patternBase.end(); iter++) {
    Tree t;
    for(int j = 0; j < iter->second.size(); j++) {
        for(int k = iter->second[j]->getPath().size() - 1; k >= 0 ; k--)
            sets.push(iter->second[j]->getPath()[k]);

        t.insertNode(sets, here I want to use last pair (value) of allCount[x] map);
        cout << endl;
    }
    cout << endl;
    x++;
}

您需要像这样创建迭代器:

multimap<string, int>::iterator it = allCount[x].end();

然后递减它使它指向最后一个元素:

it--;

最后:

t.insertNode(sets, it->second);