std::map<int, CString> m;
m[1] = TEXT("1");
m[2] = TEXT("2");
m.insert(std::pair<int, CString>(3, TEXT("3")));
m.insert(std::pair<int, CString>(4, TEXT("4")));
m.insert(std::map<int, CString>::value_type(5, TEXT("5")));
m.insert(std::map<int, CString>::value_type(6, TEXT("6")));
m.insert(std::make_pair(7, TEXT("7")));
m.insert(std::make_pair(8, TEXT("8")));
<pre name="code" class="cpp">std::map<int 字体点数大小, int 字体高度> m_mapFontSize;
查找
m_pTabelFont->lfHeight = m_mapFontSize.find(nPointSize)->second;
反向查找
int nFontSize = 0;
std::map<int, int>::iterator itBegin = m_mapFontSize.begin();
std::map<int, int>::iterator itEnd = m_mapFontSize.end();
while (itBegin != itEnd)
{
if (itBegin->second == m_pTabelFont->lfHeight)
{
nFontSize = itBegin->first;
break;
}
itBegin++;
}