<分区>
我使用以下几行创建了一个 HashMap 和一个迭代器:
std::map<const char*,vaLueClass *> myCache;
std::map<const char*,vaLueClass *>::iterator myCacheIterator;
然后我使用下面的行插入到这张 map 中:
myCache[anotherObject->getStringKey()] = new vaLueClass(anotherObj1->getIntAttr(), anotherObj1-->getIntAttr());
然后,每当我尝试使用下面的行搜索此 map 或螺母中是否存在特定字符串的条目时,它总是进入 IF block ,换句话说,它在其中找不到任何条目这张 map 。
myCacheIterator= myCache.find(sampleObject->getstringKey());
注意:此处 sampleObject->getstringKey()
返回之前插入的相同键。
if (myCacheIterator.operator ==(myCache.end())){
// this block means that no matched entry is found inside the map myCache
}
此外,这是在 C++ 中创建和使用 std::map 的正确方法吗?如果没有,请推荐一个。
此外,我还没有使用关键字 new
来创建 std::map 对象。