//
创建一个存储字符串的哈希表,同时使每个字符串都和一个整数相关联
CMap < CString,LPCTSTR, int , int > MyMap;
// 插入字符串(同时可以去重)
CString newstr = " xxxx " ;
MyMap.SetAt(newstr, 1 );
// 如果想在插入同时记录所插入的字符串在CMap中重复的次数
int count;
if ( ! MyMap.Lookup(newstr, count))
... {
MyMap.SetAt(newstr, 1);
}
else
... {
MyMap.SetAt(newstr, ++count);
}
// 遍历、输出CMap
CMap < CString,LPCTSTR, int , int > MyMap;
// 插入字符串(同时可以去重)
CString newstr = " xxxx " ;
MyMap.SetAt(newstr, 1 );
// 如果想在插入同时记录所插入的字符串在CMap中重复的次数
int count;
if ( ! MyMap.Lookup(newstr, count))
... {
MyMap.SetAt(newstr, 1);
}
else
... {
MyMap.SetAt(newstr, ++count);
}
// 遍历、输出CMap
POSITION pos = MyMap.GetStartPosition();
CString item;
while (pos!=NULL)
...{
MyMap.GetNextAssoc(pos,item,count);
AfxMessageBox(item);
}
CString item;
while (pos!=NULL)
...{
MyMap.GetNextAssoc(pos,item,count);
AfxMessageBox(item);
}