#include using namespace std;int _tmain(int argc, _TCHAR* argv[]){ CMap #include using namespace std;int _tmain(int argc, _TCHAR* argv[]){ CMap

CMap的简单应用示例

代码如下

#include "stdafx.h"
#include <afxtempl.h>
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	CMap<CString, LPCTSTR, CString, LPCTSTR> map;
	CString strKey;
	CString strVal;
	//添加
	for (int i=0;i<5;i++)
	{
		strKey.Format(L"KEY%d",i);
		strVal.Format(L"VAL%d",i);
		map.SetAt(strKey,strVal);
	}
	//遍历
	POSITION pos = map.GetStartPosition();
	while (pos)
	{
		map.GetNextAssoc(pos,strKey,strVal);
		wcout<<(LPCTSTR)strKey<<L" : "<<(LPCTSTR)strVal<<endl;
	}
	//查找
	CString strFindKey(L"KEY3");
	CString strFoundVal;
	if (map.Lookup(strFindKey,strFoundVal))
	{
		wcout<<(LPCTSTR)strFindKey<<"--->"<<(LPCTSTR)strFoundVal<<endl;
	}
	system("pause");
	return 0;
}

结果输出:

2011041310081221.jpg

注:VS2005控制台程序应用MFC类,需做如下设置:

2011041310130891.jpg

2011041310132330.jpg

转载于:https://www.cnblogs.com/dahai/archive/2011/04/13/2014453.html

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值