typedef CMap<CString*, CString*, CString*, CString*> CStrPtrMap; 个中缘由,当然还是出于对效率的考虑,我们在SetAt之前先new出一个CString对象,然后将其填入CStrPtrMap,这样的好处在于我们在SetAt的时候不需要去调用CString的赋值构造函数,而仅仅作简单的数据拷贝,这样的行为几乎适合所有的复杂数据结构,包括类,结构...
而且因为MFC只有专门的实现LPCSTR和LPCWSTR,而不是CStringA和CStringW,如果你想在CMap中使用CString,你必须声明CMap<CString, LPCTSTR...>。 好了,现在你知道CMap是如何计算哈希值的了,但是由于多个键可能有相同的哈希值,CMap需要遍历整个链表来找到一个键“content”完全相同的键,而不仅仅是相同的“哈希值”。当CMap...
CMap<CString,LPCTSTR,CString,LPCTSTR>my_Map; CString strKey = _T(""); CString strValue = _T(""); my_Map.SetAt("1","hello");//添加元素CString pLook; my_Map.Lookup("1",pLook);//查找元素ShowMessage(pLook.GetBuffer(pLook.GetLength()));intc = my_Map.GetCount(); my_Map.RemoveAll()...
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 #include <afxtempl.h> CMap<CString,LPCTSTR,CString,LPCTSTR>my_Map; CString strKey = _T(""); CString strValue = _T(""); my_Map.SetAt("1","hello");//添加元素 CString pLook; ...
CArray,CList,CMap如何实例化,1、定义一个CMap,向这个CMap中增加数据项(键-值对)。CMapm_ItemMap;CStringstrKey=_T(""),str=_T("");inti;for(i=0;iCStrMap;显然,向这样的用法,是无可厚非的,就像我们国家的中医,在经过无数次致命的尝试之...
typedef CMap<int, int, CString, CString> CMapStu; 使用时,我们认为CMapStu是一个类型就可以了。 CMapStu m_class1; //班级1 3.添加:void SetAt(ARG_KEY key, ARG_VALUE newValue); 此函数会以Key值遍历列表,当查找到key值后使用newValue替换以前的Value值。如果没有找到key值,则添加此项。
CMap<CString, LPCTSTR, CString, LPCTSTR>m_ItemMap; CString strKey = _T(""), str = _T(""); int i; for(i = 0; i < 5; i++) { strKey.Format("%d", i);//这个是键 str.Format("A%d", i);//键对应的值 m_ItemMap.SetAt(strKey, str); ...
CMap不能用CString作为键类型,推荐使用std::map。参考资料:http://www.cppblog.com/flyingxu/archive/2005/12/27/4274.html
CMap<CString,LPCTSTR,CString,LPCTSTR>my_Map; CString strKey = _T(""),strValue = _T(""); int i; for(i=0;i<5;i++) { strKey.Format("%d",i); strValue.Format("V%d",i); my_Map.SetAt(strKey,strValue); } 2.遍历整个CMap的常用方法 ...