定义一个结构体变量,输入数据,输出变量内容。
主函数如下:
int main() { student student1; cin>>student1.num>>student1.name>>student1.sex>>student1.score; cout<<student1.num<<' '<<student1.name<<' '<<student1.sex<<' '<<student1.score; return 0; }
提交时只提交主函数以外部分
输入
1001 lihong f 89.7
输出
1001 lihong f 89.7
#include<iostream>
using namespace std;
struct student
{
long num;
char name[20];
char sex;
float score;
}std1;
int main()
{
student student1;
cin>>student1.num>>student1.name>>student1.sex>>student1.score;
cout<<student1.num<<' '<<student1.name<<' '<<student1.sex<<' '<<student1.score;
return 0;
}