我有 2 个元素(目前)地图:
#define IDI_OBJECT_5001 5001
#define IDI_OBJECT_5002 5002
/.../
ResourcesMap[IDI_OBJECT_5001] = "path_to_png_file1";
ResourcesMap[IDI_OBJECT_5002] = "path_to_png_file2";
我正在尝试实现搜索此地图的方法。我正在传递字符串参数(文件路径)和方法返回 int(地图的键值)
int ResFiles::findResForBrew(string filePath)
{
string value = filePath;
int key = -1;
for (it = ResourcesMap.begin(); it != ResourcesMap.end(); ++it)
{
if (/*checking if it->second == value */)
{
key = it->first;
break;
}
}
return key;
}
类 ResFiles { public: ResFiles(); ~ResFiles();
map <int, string> ResourcesMap;
map <int, string>::const_iterator it;
void filenamesForBrew();
int findResForBrew(string filePath);
private:
};
我如何检查它何时->秒-> ==值,然后返回该键?我将不胜感激。提前致谢。