如何获得多重映射中的所有唯一键 [英] How can I get all the unique keys in a multimap
本文介绍了如何获得多重映射中的所有唯一键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个多图,我想要所有的唯一键存储在一个向量。
I have a multimap and I want get all the unique keys in it to be stored in a vector.
multimap<char,int> mymm;
multimap<char,int>::iterator it;
char c;
mymm.insert(pair<char,int>('x',50));
mymm.insert(pair<char,int>('y',100));
mymm.insert(pair<char,int>('y',150));
mymm.insert(pair<char,int>('y',200));
mymm.insert(pair<char,int>('z',250));
mymm.insert(pair<char,int>('z',300));
我该如何做?有一种方法来计算具有键的元素的数目,但是没有计算多重映射中的唯一键的数目。
How can I do this? there is way to count number of elements with a key but none to count number of unique keys in a multimap.
已添加:由唯一我是指多重映射中的所有键 - 它们可以在多重映射中重复或发生一次。
Added: By unique I mean all the keys in multimap once - they can be repeated or occur once in multimap.
这样唯一的键是 - x , y 和 z
So unique keys here are - x, y and z
推荐答案
我试过这个和它工作
for( multimap<char,int>::iterator it = mymm.begin(), end = mymm.end(); it != end; it = mymm.upper_bound(it->first))
{
cout << it->first << ' ' << it->second << endl;
}
这篇关于如何获得多重映射中的所有唯一键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文