質問

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!

役に立ちましたか?

解決

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...
}

他のヒント

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"];
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top