#include<iostream>
using namespace std;
//定义一个结构体
struct StudentInfo
{
string name;
int age;
double score;
}stu2, stu3 = {"小明",19,65.0};
//输出一个数据对象的完整信息
void printInfo(StudentInfo stu) {
cout << "学生姓名:" << stu.name << "\t年龄:" << stu.age << "\t成绩:" << stu.score << endl;
}
int main()
{
//创建数据对象并做初始化
StudentInfo stu = {"张三",18,75.0};
StudentInfo stu1{ "李四",20,82 };
StudentInfo stu4 = stu3;
//访问数据
stu2.name = "王五";
stu2.age = 22;
stu2.score = 79.5;
printInfo(stu);
printInfo(stu2);
//结构体数组
StudentInfo s[3] = {
{"a",17,89.2},
{"b",88,31.4},
{"c",33,73.5}
};
printInfo(s[1]);//{"b",88,31.4}
cout << s[2].age << endl;//b的年龄
for (StudentInfo stu : s) {
printInfo(stu);
}
cin.get();
}