8.3结构体数组
#include <iostream>
#include<string>
using namespace std;
//1.创建一个结构体
struct student
{
string name;
int age;
int score;
};
int main8_3()
{
//2.创建一个结构体数组
struct student starray[3] =
{
{ "zz", 18, 100 },
{ "xx", 28, 99 },
{ "cc", 38, 66 },
};
//3.遍历结构体数组
starray[2].name = "aaa";
for (int i = 0; i < 3; i++)
{
cout << "sss" << starray[i].name << endl;
}
system("pause");
return 0;
}
# 8.2结构体的使用
#include <iostream>
using namespace std;
#include<string>
/*
语法:struct 结构体名(结构体成员列表)
*/
struct student
{
string name;
int age;
int score;
}s3;
//创建具体学生,有三种
/*
struct student s1
struent student s1={...};
在定义结构体后创建
*/
int main8_1()
{
//下面struct可以省略
struct student s1;
s1.age = 10;
s1.name = "ddddd";
s1.score=88;
struct student s2 = {"dddd",11,22};
cout << "姓名:" << s2.age << endl;
system("pause");
return 0;
}