- 1.结构体嵌套结构体
struct student
{
string name;
int age;
int score;
};
struct teacher
{
int number;
string name;
int age;
struct student stu;
};
void print_struct(struct student* p) {
cout << "学生姓名:" << p->name << endl
<< "学生分数:" << p->score << endl;
}
teacher t;
t.name="老王";
t.age = 28;
t.number = 1;
t.stu.name = "小王";
t.stu.age = 10;
t.stu.score = 100;
cout << "老师的姓名:" << t.name << endl
<< "老师的年龄: " << t.age << endl
<< "老师的学生: " << t.stu.name << endl;
print_struct(&t.stu);//地址传入
- 2.获取字符串的第几个字符
#include
string nameSeed="ABCDE";
void allocate(struct Teacher tArray[],int len){
for(int i =0;i
tArray[i].name = "Teacher_";
tArray[i].name += nameSeed[i];//直接字符串nameSeed[i],就行
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)