STL 映射不会擦除
STL Map doesn't erase
我的程序中有以下方法。
奇怪的是,在我调用擦除后,数据不会被删除。
知道吗?
map<int,obj>::iterator it = this->indexMap.find(id);
if(it != this->indexMap.end())
{
int mapSize = this->indexMap.size();
int dataSize = (*it).second.getDataMap().size();
//copy data to another node | even when it doesn't get into this if condition, it does not remove the data
if(mapSize> 1 && dataSize != 0)
{
it++;
this->copyData(id,it->first);
it--;
}
//remove peer | i've tried id and it, both does not work
this->indexMap.erase(it);
map<int,obj>::iterator iter = this->indexMap.find(id);
if(iter == this->indexMap.end())
{
cout << "ERROR" << endl;
}
}
输出:
ERROR
谢谢! :)
此块:
map<int,obj>::iterator iter = this->indexMap.find(id);
if(iter == this->indexMap.end())
{
cout << "ERROR" << endl;
}
如果地图中找不到具有键id
的元素,则打印出ERROR
。因此,它已被删除。
相关文章:
- 在映射擦除c++期间执行循环的次数
- 如何编写用于多映射插入和擦除功能的 API?
- 擦除映射 c++ 中其他键的值中已存在的那些值
- 在c++中擦除后在映射上迭代时出现的奇怪问题
- 为什么擦除C++映射类成员中的值?
- std::map 擦除 - 将迭代器传递给错误的映射
- 如何在下一次函数调用中使用 STL 映射擦除从最后一个位置
- 在向量和映射上执行擦除(迭代器)时观察到的不同行为
- 映射::擦除:按键擦除或迭代器擦除之间的区别
- 擦除C++映射中包含单个值的密钥
- 有没有一种方法可以防止在STL无序映射上插入或擦除
- C++查找并擦除多映射元素
- 在C++STL映射上通过迭代器擦除
- 在没有c++11的情况下,擦除映射中最后插入的元素的正确方法是什么
- C++在擦除时循环通过映射
- 与C++中擦除映射迭代器的行为不一致
- 使用 equal_range() 和 erase() 擦除多映射中除一对之外的所有对
- STL 映射不会擦除
- C++ 映射擦除范围
- STL 允许使用指向不同映射的迭代器擦除映射的键/值?