C++ CMap查找PLookup的使用 找不到已插入的原因。 求高手指教!!!
#include<iostream>
#include<string>
#include<afxtempl.h>
#include<atlcoll.h>
using namespace std;
struct word
{
int time;
string w;
word(int t,string s)
{
w =s;
time =t;
}
word(){}
};
void LookUP(CMap<const char *,const char*,word,word &> &mymap)
{
string a="zzg";
word newword(1,a);
CMap<const char *,const char*,word,word &>::CPair * p_pair = mymap.PLookup("zzg");
//或者 CMap<const char *,const char*,word,word &>::CPair * p_pair = mymap.PLookup(newword.w.c_str());
cout<<p_pair->value.w <<endl;
}
void main()
{
CMap<const char *,const char*,word,word &> mymap;
word myw1(2,"zzg"),myw2(4,"tf"),myw3;
mymap.SetAt (myw1.w.c_str(),myw1);
mymap[myw2.w.c_str()]=myw2;
LookUP(mymap);
size_t index = 0;
const char * pszkey;
POSITION ps = mymap.GetStartPosition();
while(ps)
{
mymap.GetNextAssoc(ps,pszkey,myw3);
printf("index:%d,key:%s,word:%s,time:%d\n",++index,pszkey,myw3.w.c_str(),myw3.time);
}
}
在LookUP()函数中两种方法p_pair 的值都为空(表示没找到),这是为什么呢!!!!
高手求指导啊!!!