Reputation: 11399
I have a
map <wstring,wstring>.
I have inserted pairs like this:
m_Translations.Content().insert(pair<wstring,wstring>(L"rome",L"roma"));
m_Translations.Content().insert(pair<wstring,wstring>(L"water",L"aqua"));
How could I determine the translation for "water" from the map? In other words: I would like to get the second item from the first. The search is case-sensitive.
Thank you for the help!
Upvotes: 0
Views: 3290
Reputation: 2245
You can use operator[] available on std::map
.
For example:
map<wstring, wstring> myMap = m_Translations.Content();
myMap.insert(pair<wstring, wstring>(L"rome", L"roma"));
myMap.insert(pair<wstring, wstring>(L"water", L"aqua"));
// waterText value would be 'aqua'
wstring waterText = myMap[L"water"];
Upvotes: 3
Reputation: 21769
A bit weird question. What about the default way of accessing a map with operator[]
?
wstring aqua = m_Translations.Content()[L"water"];
In case you are not sure whether a translation exists or not, you can check it with the find
method:
const auto& dict = m_Translations.Content();
auto pAqua = dict.find(L"water");
if (pAqua != dict.end())
{
// Found it!
}
else
{
// Not there...
}
Upvotes: 4