首先我们得看下如何在CMap中进行映射,以及如何进行遍历整个映射…… #include <afxwin.h> #include <afxtempl.h> #include <iostream> using std::cout; using std::endl; int main() { setlocale( LC_CTYPE, "chs" ); CMapStringToString map; map[_T("Sunday")] = _T("星期天"); map[_T("Monday")] = _T("星期一"); map[_T("Tuesday")] = _T("星期二"); map[_T("Wednesday")] = _T("星期三"); map[_T("Thursday")] = _T("星期四"); map[_T("Friday")] = _T("星期五"); map[_T("Saturday")] = _T("星期六"); POSITION pos = map.GetStartPosition(); while(pos != NULL) { CString strKey, strItem; map.GetNextAssoc(pos, strKey, strItem); TRACE(_T("key = %s/titem = %s/n"), strKey, strItem); } } Lookup成员方法展示: #include <afxwin.h> #include <afxtempl.h> #include <iostream> using std::cout; using std::endl; int main() { setlocale( LC_CTYPE, "chs" ); CMapStringToString map; map[_T("Sunday")] = _T("星期天"); map[_T("Monday")] = _T("星期一"); map[_T("Tuesday")] = _T("星期二"); map[_T("Wednesday")] = _T("星期三"); map[_T("Thursday")] = _T("星期四"); map[_T("Friday")] = _T("星期五"); map[_T("Saturday")] = _T("星期六"); POSITION pos = map.GetStartPosition(); while(pos != NULL) { CString strKey, strItem; map.GetNextAssoc(pos, strKey, strItem); TRACE(_T("key = %s/titem = %s/n"), strKey, strItem); } TRACE(_T("Lookup成员方法展示:/n")); CString strItem; if(map.Lookup(_T("Friday"), strItem)); TRACE(_T("Firday的中文翻译是:%s/n"), strItem); } 我们暂且看一下DEBUG输出: key = Tuesday item = 星期二 key = Saturday item = 星期六 key = Wednesday item = 星期三 key = Thursday item = 星期四 key = Friday item = 星期五 key = Monday item = 星期一 key = Sunday item = 星期天 Lookup成员方法展示: Firday的中文翻译是:星期五 没有问题!!! RemoveKey展示: #include <afxwin.h> #include <afxtempl.h> #include <iostream> using std::cout; using std::endl; int main() { setlocale( LC_CTYPE, "chs" ); CMapStringToString map; map[_T("Sunday")] = _T("星期天"); map[_T("Monday")] = _T("星期一"); map[_T("Tuesday")] = _T("星期二"); map[_T("Wednesday")] = _T("星期三"); map[_T("Thursday")] = _T("星期四"); map[_T("Friday")] = _T("星期五"); map[_T("Saturday")] = _T("星期六"); map.RemoveKey(_T("Friday")); POSITION pos = map.GetStartPosition(); while(pos != NULL) { CString strKey, strItem; map.GetNextAssoc(pos, strKey, strItem); TRACE(_T("key = %s/titem = %s/n"), strKey, strItem); } int len = map.GetCount(); TRACE(_T("还有%d个映射项目/n"), len); }