[C/C++基礎]- 純C++動態配置字串陣列利用結構實現
[C/C++基礎]- 純C++動態配置字串陣列利用結構實現
本篇要分享純C++動態配置字串陣列利用結構實現,有興的(C/P)同好,歡迎來(C/P)一下,哈哈 ^ ^。
程式碼 |
#include <cstdlib> #include <cstring> #include <iostream> struct FileData{ int intnumber; char chrData[500]; };
usingnamespace std;
int main(int argc, char *argv[]) {
FileData *FD;
FD=new FileData[2]; (FD+0)->intnumber=0;
strcpy((FD+0)->chrData,"liao jash");
(FD+1)->intnumber=1;
strcpy((FD+1)->chrData,"jash.liao");
int i=0; for(i=0;i<2;i++) {
cout<<(FD+i)->intnumber<<":"<<(FD+i)->chrData<<"\n";
}
system("PAUSE");
return EXIT_SUCCESS; }
|