关于CMap类的使用~~~ 能提供任何类型到任何类型的映射???
CMap模板类能提供任何对象到任何对象的映射吗??? 是任何吗?
我用CString作为它的 KEY, 编译时出错了:
error C2440: “类型转换” : 无法从“CString”转换为“DWORD_PTR”
出错地方是MFC库文件 afxtempl.h
哪位大哥遇到过这个问题啊? 该怎么解决呢?
问题点数:0、回复次数:4Top
1 楼newcore(to be or not to be, it's a question.)回复于 2005-06-04 12:45:15 得分 0
用CString作为key是可以的:
给你写了个demo:
#include <Afxtempl.h>
typedef CMap<CString, LPCTSTR, CString, CString> MapStr2Str;
MapStr2Str map ;
void CheckMap()
{
map.SetAt("first", "first string");
map.SetAt("second", "second string");
map.SetAt("third", "third string");
POSITION pos = map.GetStartPosition();
while( pos!=NULL )
{
CString strKey;
CString strVal;
map.GetNextAssoc(pos, strKey, strVal);
printf("map %s => %s\n", strKey, strVal);
}
}
run一下吧.Top
2 楼Jans(网事如风)回复于 2005-06-04 13:49:52 得分 0
Search "COLLECT sample (MFC)" in MSDNTop
3 楼sursure(答案)回复于 2005-06-04 13:52:33 得分 0
谢谢老Top
4 楼krh2001(边城浪子)回复于 2005-06-04 14:01:58 得分 0
可以排序的类型都可以作为MAP的KEY
串到串的映射(MFC):
typedef CMap<CString, CString&, CString, CString&> Str2Str;
(STL版)
typedef std::map<std::string, std::string> Str2Str;
Top




