Linux使用hash_map遇到问题

zmzbs123 zmzbs123 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include <ext/hash_map>
using namespace __gnu_cxx;
class str_hash{
public:
size_t operator()(const string& str) const
{
unsigned long __h = 0;
for (size_t i = 0 ; i < str.size() ; i ++)
__h = 5*__h + str[i];
return size_t(__h);
}
};

class str_compare
{
public:
bool operator()(const string& str1,const string& str2)const
{return str1==str2;}
};
int main()
{

hash_map<string,string,str_hash,str_compare>::iterator iter=nouns.find(name);
if (iter == nouns.end())
{
cout<<iter->first<<endl;////每次都core在这里
}
}

每次都core的地方:
0x004cc43c in std::operator<< <char, std::char_traits<char>, std::allocator<char> > () from /usr/lib/libstdc++.so.6

各位达人,请问这是神马原因呢?



...全文
评论 2
收藏 已收藏
分享
返回顶部
zmzbs123
工具平台和程序库 24,850 成员 27,330 内容