資源簡介
C++實戰源碼-用new動態創建結構體(入門級實例087).zip
代碼片段和文件信息
//?new.cpp?:?Defines?the?entry?point?for?the?console?application.
//
#include?“stdafx.h“
#include?“iostream.h“
//人員信息
struct?Person
{
char?ID[6];//編號
char?Name[10];//姓名
};
int?main(int?argc?char*?argv[])
{
int?len?=?3;//總人數
int?structinfo[10];//存信息的數組
for?(int?i?=?0;i {
Person?*p?=?new?Person;//動態創建結構變量
structinfo[i]?=?(int)p;//存入數組
cout?<“請輸入第“?< cin?>>?p->ID;
cout?<“請輸入第“?< cin?>>?p->Name;
}
for?(?i?=?0;?i {
Person?*p?=?(Person?*)structinfo[i];//取出變量
cout?<“第“?<ID?<“\n“;
cout?<“第“?<Name?<“\n“;
delete?[]?p;
}
return?0;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????794??2010-09-25?13:35??new\new.cpp
?????文件????????4500??2010-09-25?13:20??new\new.dsp
?????文件?????????531??2010-09-25?13:20??new\new.dsw
?????文件?????????290??2010-09-25?13:20??new\StdAfx.cpp
?????文件?????????769??2010-09-25?13:20??new\StdAfx.h
- 上一篇:C++實戰源碼-將AVI動畫分解成BMP位圖
- 下一篇:C++實戰源碼-抓不住的兔子
評論
共有 條評論