chapter4-16.cpp

来自「大量程序实例」· C++ 代码 · 共 39 行

CPP
39
字号
//文件夹名称:CHAPTER4-16.cpp
#include<iostream.h>
#include<afxcoll.h>
#include<afxtempl.h>
class A
{
    int age;
public:
	   A(){}
	A(int x):age(x){}
	void operator!(){cout<<age<<endl;}
	void operator=(int x){age=x;}
};
void main()
{
  A *p;
  int l,c[5];
  CArray<A,A> array;
  for(int i=0;i<5;i++)
  {
    cout<<"Please input Age data:";
cin>>l;
p=new A(l);
c[i]=array.Add(*p);//返回索引值
  }
  cout<<"The current total number is "<<array.GetSize()<<endl<<"The second item is ";
  !array.GetAt(c[2]);//返回被插入的对象
  array.InsertAt(0,*new A(100),2);//向数组的最前端插入两个新对象
  cout<<"The current total number is "<<array.GetSize()<<endl<<"The second item is ";
  !array[2];
  array[2]=99;
  cout<<"The second item modified is ";
  !array[2];
  cout<<flush;
  cin.get();
  cin.get();
  array.RemoveAll();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?