在头文件中包含#include "afxtempl.h"
.h中声明camp的对象
typedef CMap<int, int, CString, CString>CMapIntToString;
CMapIntToString map;
.cpp中声明插入map的对象
map.SetAt(1,L"aaa");
map.SetAt(4,L"sss");
map.SetAt(100,L"sadf");
查找映射的键值
int i = 4;
CString str;
// 查找映射的键值
if (map.Lookup(i,str)) {
ASSERT(str== "sss");
AfxMessageBox(str);
}else{
AfxMessageBox(L"键值不存在");
}
// 输出map对象
int i = 0;
CString str = L"";
POSITION pos = map.GetStartPosition();// 获得初始位置
while (pos != NULL){
map.GetNextAssoc(pos, i, str);// 获得初始位置的下一个键
AfxMessageBox(str);
}