CMap的用法

zhangsss 2008-02-25 10:15:23
谁能给个简单的使用的例子呀?请不要说些找MSDN之类的话。最后介绍下用法,给个例子,谢谢啦!!!
...全文
157 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
huliang66 2008-02-27
  • 打赏
  • 举报
回复
//==============将数据存储到 CMAP中
int xxx=atoi(strc);
m_map.SetAt(xxx,rit);
根据m_dat把对应的ch查询出来
m_map.Lookup(m_dat,ch);
oakfire 2008-02-27
  • 打赏
  • 举报
回复
CMap<int,int,CPoint,CPoint> myMap;
int i;

myMap.InitHashTable( 257 );

// Add 10 elements to the map.
for (i=0;i < 200;i++)
myMap[i] = CPoint(i, i);

// Remove the elements with even key values.
CPoint pt;
for (i=0; myMap.Lookup( i, pt ) ;i+=2)
{
myMap.RemoveKey( i );
}




oakfire 2008-02-27
  • 打赏
  • 举报
回复
复制 粘贴
CMap<int,int,CPoint,CPoint> myMap;

// Add 10 elements to the map.
for (int i=0;i < 10;i++)
myMap.SetAt( i, CPoint(i, i) );

// Remove the elements with even key values.
POSITION pos = myMap.GetStartPosition();
int nKey;
CPoint pt;
while (pos != NULL)
{
myMap.GetNextAssoc( pos, nKey, pt );

if ((nKey%2) == 0)
myMap.RemoveKey( nKey );
}

#ifdef _DEBUG
afxDump.SetDepth( 1 );
afxDump << "myMap: " << &myMap << "\n";
#endif

xjchilli 2008-02-27
  • 打赏
  • 举报
回复
给你举个STL里面的map的例子,跟CMap用法应该一样的。
#include <map>
#include <string>
using namespace std;
...
map<string, string> namemap;

//增加。。。
namemap["岳不群"]="华山派掌门人,人称君子剑";
namemap["张三丰"]="武当掌门人,太极拳创始人";
namemap["东方不败"]="第一高手,葵花宝典";
...

//查找。。
if(namemap.find("岳不群") != namemap.end()){
...
}

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧