所以我有一个 std::unordered_map,我想访问存储在这个地图中的字符串。我想搜索 intro 地图内的所有单词并与给定单词进行比较。如果字符串相同,则继续执行 if 语句。
{
public:
bool CheckFoo(const char* word);
protected:
typedef std::unordered_map<std::string, bool> word_map;
word_map words_map;
};
bool CheckFoo(const char* word)
{
if (words_map.empty())
{
return false;
}
auto it = words_map.begin();
while (it != words_map.end())
{
const std::string &r = it->first;
const char* tmp = word;
if (strcmp(tmp, r.c_str() ) == 0)
{
return true;
}
}
return false;
}
if ( CheckFoo("wordFoo") )
{
// bla bla
}
问题是这些代码会生成一个 .core 转储文件。您在我的代码中看到任何错误吗?
崩溃核心分析将我指向 strcmp 行