我有一个
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"));我如何从地图上确定“水”的翻译?换句话说:我想从第一个项目中获得第二个项目。搜索区分大小写。
谢谢你的帮助!
发布于 2013-05-22 20:33:25
一个有点奇怪的问题。使用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...
}发布于 2013-05-22 20:33:12
您可以使用std::map上提供的operator[]。
例如:
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"];https://stackoverflow.com/questions/16691697
复制相似问题