gpt4 book ai didi

c++ - 在 map vector 中查找对

转载 作者:太空宇宙 更新时间:2023-11-04 16:28:00 24 4
gpt4 key购买 nike

我正在使用以下函数尝试在 map vector 中查找 map 元素的键。

Entry* SymTab::lookup(const char* name)
{
for (int i=0;i<table.size();i++) //table is the vector
{
map<const char*, Entry, ltstr>::iterator its= table.at(i).find(name);
if (its != cur.end())
{
Entry* obj = &its->second;
cout<<(*its).first<<endl;
return obj;
}


}
}

该函数正确返回第一个 vector 索引 (at(0)) 内任何项目的值。但每当我尝试访问第二个索引 (at(1)) 中的元素时,它就会出现段错误。我确定 map 已正确插入并填充在第二个索引处。

有人看到这里的问题吗?

最佳答案

Does anyone see the issue here?

是的。 cur 不跟踪当前 map 。

尝试将 if 行替换为:

if (its != table.at(i).end())

关于c++ - 在 map vector 中查找对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10076288/

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