如何在c++中比较映射中的键和值
How to compare KEYs to VALUEs in maps in C++?
我得到了HashMap的声明,它是这样的:
HashMap<String, T*> resources; //given by my professor
还提供了这个remove函数void removeResource(T* a),该函数的目标是在map中搜索参数(a),如果找到该参数,则从map中删除与该参数相关的值和键。
我所做的是:
void removeResource(T* a) //function part given by my professor
{
//find the resource and remove it from the map
for (auto it = resources.begin(); it != resources.end(); it++){
if (resources.at(it) == a)
resources.erase(it);
}
}
Visual studio编译器指向if (resources.at(it) == a).
请告诉我哪里做错了。
for (auto it = resources.begin(); it != resources.end();) {
if (it->second == a) {
it = resources.erase(it);
}
else {
++it;
}
}
相关文章:
- 在具有 std::p air 键和值的映射中添加 b2vec2
- 如何在 c++ 中创建分组多重映射键和关联值的表
- 如何将键和值从映射传输到另一个映射?
- 如何通过键和值以及在C 中的结果映射中比较两个地图?我们有任何STL API吗?
- 多重映射的每个元素是否同时包含键和值
- 如何正确使用带有智能指针和自定义类的映射作为键和值
- 如何使用 boost 连接映射的键和值,特别是如果值是结构
- 对象来映射键和值
- C++STL映射键和值工作不正常
- 使用C++中的函数指针映射枚举键和值
- 从变量映射键和值初始化
- 键和值属于同一类型的多重映射是否有任何意义
- 如何在C++中创建将键和值作为结构的映射
- 使用结构作为映射的键和值.find() 操作给出错误
- 从常量迭代器到映射向量,获取映射向量中映射元素的键和值
- std::映射绑定到所有键和值的堆的分配器
- 如何在c++中比较映射中的键和值
- 在c++中如何从另一个完整映射中插入键和值到空映射
- 在c++中交换映射的键和值
- 交换映射中的键和值