// CMap.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "CMap.h"
#include "afxtempl.h"
#include "CBean.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/
// The one and only application object
CWinApp theApp;
CMap<CString,LPCTSTR,MapInfo,MapInfo> ListMap;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
CString temp;
MapInfo mapinfo;
for (int i=110;i<120;i++)
{
temp.Format("%d",i);
mapinfo.strName = temp + "name";
mapinfo.strAdd = temp + "add";
ListMap.SetAt(temp,mapinfo);
}
// 删除
ListMap.RemoveKey("112");
//ListMap.RemoveAll();
//遍历正个CMAP的常用方法。
POSITION pos = ListMap.GetStartPosition();
while(pos)
{
ListMap.GetNextAssoc(pos, temp, mapinfo);
printf("index = %s add=: %s \r\n", temp,mapinfo.strAdd);
}
//在CMAP中查找相应的数据项。
if(ListMap.Lookup("112", mapinfo))
{
printf("add = %s \r\n", mapinfo.strAdd);
}else{
printf("mapinfo = %s \r\n", "not");
}
return 0;
}
class MapInfo
{
public:
CString strName;
CString strAdd;
protected:
private:
};