【例51】设计一个“学生”结构体,包括 姓名、性别、年龄、地址等成员。然后定 义结构体变量并进行初始化,输出显示结 果 # include≤ iostream. h> include<string.h> struct student 人民邮电出版社 POSTS tEl OM PRE 动此映
【例5.1】设计一个“学生”结构体,包括 姓名、性别、年龄、地址等成员。然后定 义结构体变量并进行初始化,输出显示结 果。 #include<iostream.h> #include<string.h> struct student
char name 10l char sex 3 int age, char adderss 100; struct student stul={"李明""男"’22,"北 京市"}; 人民邮电出版社 POSTS tEl OM PRE 动此映
{ char name[10]; char sex[3]; int age; char adderss[100]; }; struct student stu1={"李明","男",22, "北 京市"};
void maino struct student stul={"李明","男",22,"北 京市"}; cout<<stul name<<t<<stul sex<<'t'<<st ulage<<'t<<stul adderss<<endl strcpy(stu1name,"王芳"); 人民邮电出版社 POSTS tEl OM PRE 动此映
void main() { struct student stu1={"李明","男",22, "北 京市"}; cout<<stu1.name<<'\t'<<stu1.sex<<'\t'<<st u1.age<<'\t'<<stu1.adderss<<endl; strcpy(stu1.name,"王芳");
strcpy( (stul.sex,"女"); stulage=20; strcpy(stu1 adderss".津市"); cout<<stul name<<t<<stu l sex<<t'<<st ul.age<<'it<<stul adderss<<endl 人民邮电出版社 POSTS tEl OM PRE 动此映
strcpy(stu1.sex,"女"); stu1.age=20; strcpy(stu1.adderss,"天津市"); cout<<stu1.name<<'\t'<<stu1.sex<<'\t'<<st u1.age<<'\t'<<stu1.adderss<<endl; }
程序运行后,输出结果为: 李明男22北京市 王芳女20天津市 人民邮电出版社 POSTS tEl OM PRE 动此映
程序运行后,输出结果为: 李明 男 22 北京市 王芳 女 20 天津市