#include<iostream>
#include<string>
using namespace std;
class zxl{
public:
struct z{
int num;
char *name;
char sex;
int age;
float score;
char *addr;
}z_1;
void zxl_1();
};
void zxl::zxl_1(){
cout<<z_1.num<<" "<<z_1.name<<" "<<z_1.sex<<" "<<z_1.age<<" "<<z_1.score<<" "<<z_1.addr<<" "<<endl;
}
int main(){
zxl zx;
cout<<"启始数据"<<endl;
zx.z_1.num=1001;
zx.z_1.name="zxl";
zx.z_1.sex='n';
zx.z_1.age=21;
zx.z_1.score=111;
zx.z_1.addr="helloworld";
zx.zxl_1();
cout<<"手动输入数据数据"<<endl;
cout<<"num:"<<endl;
cin>>zx.z_1.num;
cout<<"name:"<<endl;
char array[20];
zx.z_1.name=array;
cin>>zx.z_1.name;
cout<<"sex:"<<endl;
cin>>zx.z_1.sex;
cout<<"age:"<<endl;
cin>>zx.z_1.age;
cout<<"score:"<<endl;
cin>>zx.z_1.score;
cout<<"addr:"<<endl;
char array1[20];
zx.z_1.addr=array1;
cin>>zx.z_1.addr;
zx.zxl_1();
system("pause");
return 0;
}
c++ 结构体练习 结构体重的char数组指针
最新推荐文章于 2024-06-08 18:37:23 发布