實例:老師輔導學生
#include <iostream>
using namespace std;
#include<string>
/*
定義學生和老師兩個結構體
*/
struct Student
{
string name;
int age;
int score;
};
struct Teacher
{
int id;
string name;
int age;
struct Student s1;
};
int main()
{
struct Teacher t1;//創建老師結構體變量
t1.id = 1;
t1.name = "李老師";
t1.age = 48;
t1.s1.name = "小紅";
t1.s1.age = 19;
t1.s1.score = 59;
cout <<"老師姓名:" <<t1.name<<" "<< "老師輔導的學生姓名:"<<t1.s1.name << endl;
system("pause");
return 0;
}