chapter4-18.cpp
来自「大量程序实例」· C++ 代码 · 共 32 行
CPP
32 行
//文件夹名称:CHAPTER4-18.cpp
#include<afx.h>
#include<afxcoll.h>
#include<iostream.h>
class A:public CObject
{
WORD age;
public:
A(WORD x):age(x){}
WORD operator!(){return age;}
};
void main()
{
WORD l=0,k;
A *p;
CMapWordToOb map;
for(int i=0;i<5;i++)
{
while(l==0)cin>>l;
if(i==3)k=l;
p=new A(l);
map.SetAt(!*p,(A*)p);//如果键值相同,则以新换旧
l=0;
}
cout<<"The total number is "<<map.GetCount()<<endl;
if(map.Lookup(k,(CObject*&)p))cout<<!*p;//如果返回值不为零则p将得到该对象的地址
cout<<flush;
cin.get();
map.RemoveAll();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?