C++基础-数组,结构联合

有了基本数据类型之后,还不够用,这是需要对基本数据进行扩展,于是就有了数组和复合数据类型.

1.先在h中定义数据

//data.h文件
#include "stdio.h"
#include "iostream.h"
#include <string>
#if !defined(AFX_123)

int apple[100];

struct Student
{
int age;
int height;
int weight;
};

#define AFX_123
#endif

2. 在cpp中进行演示

#include "data.h"

void main()
{
Student stu[2];

//对简单数组apple初始化
for(int i=0; i<100; i++)
apple[i]=i;

//对简单的复合数据进行初始化
for(i=0; i<2; i++)
{
cin>>stu[i].age>>endl;
cin>>stu[i].height>>endl;
cin>>stu[i].weight>>endl;
}

//显示结果
//省略....

}

 

posted @ 2013-01-03 07:50  血洗女生宿舍  阅读(127)  评论(0编辑  收藏  举报