本文介绍了STL 多图删除/擦除值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有 STL Multimap,我想从映射中删除具有特定值的条目,我不想删除整个键,因为该键可能映射到其他需要的值.
I have STL Multimap, I want to remove entries from the map which has specific value , I do not want to remove entire key, as that key may be mapping to other values which are required.
请提供任何帮助.
推荐答案
如果我理解正确,这些值可以出现在任何键下.如果是这种情况,您将不得不迭代您的多重映射并删除特定值.
If I understand correctly these values can appear under any key. If that is the case you'll have to iterate over your multimap and erase specific values.
typedef std::multimap<std::string, int> Multimap;
Multimap data;
for (Multimap::iterator iter = data.begin(); iter != data.end();)
{
// you have to do this because iterators are invalidated
Multimap::iterator erase_iter = iter++;
// removes all even values
if (erase_iter->second % 2 == 0)
data.erase(erase_iter);
}
这篇关于STL 多图删除/擦除值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!