I have a map declared like this:
std::map<const char*, const char*> map2D;
The map is filled by the output from an API function, which returns const char*
:
map2D.insert(std::pair<const char*, const char*>(TempA, TempB));
Now there are 50 TempA
values and 50 TempB
values, and there is one key with the name of "months". When I am searching for this key, I am getting "not found". E.g.:
std::map<const char*, const char*>::iterator it;
it = map2D.find("months");
if (it != map2D.end())
{
std::cout << "Found " << it->first << " " << it->second << '
';
}
else
{
std::cout << "Not found
";
}
But when I am doing it like this:
map2D.insert(std::pair<const char*, const char*>("months", "June");
I can find the respective month. After searching the web, I understand that this problem may be related to the use of const char*
. Can anyone further clarify this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…