我有一个
map <wstring,wstring>.
我插入了这样的对:
m_Translations.Content().insert(pair<wstring,wstring>(L"rome",L"roma"));
m_Translations.Content().insert(pair<wstring,wstring>(L"water",L"aqua"));
我如何从地图中确定“水”的翻译?换句话说:我想从第一个项目中获得第二个项目。搜索区分大小写。
感谢您的帮助!
有点奇怪的问题。使用 访问地图的默认方式operator[]呢?
wstring aqua = m_Translations.Content()[L"water"];
如果您不确定翻译是否存在,您可以使用以下find方法进行检查:
const auto& dict = m_Translations.Content();
auto pAqua = dict.find(L"water");
if (pAqua != dict.end())
{
// Found it!
}
else
{
// Not there...
}
您可以使用std::map.
例如:
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"];