复制 粘贴 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
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 ); }
#include <map>
#include <string>
using namespace std;
...
map<string, string> namemap;//增加
namemap["岳不群"]="华山派掌门人,人称君子剑";
namemap["张三丰"]="武当掌门人,太极拳创始人";
namemap["东方不败"]="第一高手,葵花宝典";
...//查找。。
if(namemap.find("岳不群") != namemap.end()){
...
}
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
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 );
}