c++,关于如何用cin给结构体中元素赋值的问题4
发布网友
发布时间:2023-09-30 04:07
我来回答
共1个回答
热心网友
时间:2024-11-23 23:52
#include<iostream>
#include<string>
struct xinxi
{
char fname[20];
char lname[20];
char gread[20];
int age;
};
int main()
{
using namespace std;
xinxi xinxi1;//注意定义结构体变量,而不是用xinxi
cout<<"What is your first name ? "<<endl;
cin.getline(xinxi1.fname,20);
cout<<"What's your last name ?"<<endl;
cin>>xinxi1.lname;
cout<<"What latter grade do you deserve ?"<<endl;
cin>>xinxi1.gread;
cout<<"What's your age ?"<<endl;
cin>>xinxi1.age;
cout<<"Name: "<<xinxi1.lname<<','<<xinxi1.fname<<endl;
cout<<"Grade: "<<xinxi1.gread<<endl;
cout<<"Age: "<<xinxi1.age<<endl;
return 0;
}