结构体基础案例
结构体案例1:创建老师以及学生结构体,3名老师结构体中包含5名学生的结构体数组,完成后输出老师以及学生的成绩信息。
#include <string>
//C++中使用字符串需要添加string头文件
#include "iostream"
using namespace std;
struct Student
{
string name;
int age;
int score;
};
//Student结构体要放在前面,放在后面会报错,不然就要先声明
struct Teacher
{
string name;
struct Student sArray[5];
};
void allocateSpace(struct Teacher tArray[],int len)
{
string nameSeed = "ABCDE";
for (int i= 0; i < len; i++)
{
tArray[i].name = "Teacher_";
tArray[i].name += nameSeed[i];
for (int j = 0; j < 5; j++)
{
tArray[i].sArray[j].name =