gpt4 book ai didi

c++ - std::map 发现在 C++ 中不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:13:38 24 4
gpt4 key购买 nike

<分区>

我使用以下几行创建了一个 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 对象。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com