我在 if 语句中使用 map.find(key) 和 map.end() 函数:
if( p_Repos->returnTypeMap().find(tc[0]) != p_Repos->returnTypeMap().end() )
但它不起作用,我收到一个 Microsoft Visual C++ 运行时库错误,告诉我“表达式:列表迭代器不兼容”。tc[0] 只是一个字符串,我的地图中的关键位置是一个字符串。
但是,它们应该是兼容的,对吧?
任何帮助是极大的赞赏。
谢谢,汤姆
编辑:根据此处找到的答案:Finding value in unordered_map,我相信这应该可以正常工作。
第二次编辑:
这是 returnTypeMap() 函数:
std::unordered_map <std::string, std::pair<std::string, std::string>> returnTypeMap()
{
return typeTable;
}
这是我的地图的定义:
std::unordered_map <std::string, std::pair<std::string, std::string>> typeTable;