结构是一种比数组更灵活的数据格式,并且与int或其他数据类型一样,结构也能创建数组,叫做结构数组; 结构中的成员数据通过成员运算符访问。 初始化:有两种初始化方式(其他数据类型类似)
struct Student
{
char name
[20];
string Number
;
double grade
;
};
int main()
{
Student id1
= { "Young","S1809W0657",99.0 };
Student id2
{ "Kobe","S1809W0656",98.0 };
cout
<< "姓名:" << id1
.name
<< endl
<< "学号:" << id1
.Number
<< endl
<< "成绩:" << id1
.grade
<< endl
;
Student id
[50];
id
[0] = { "Kobe","S1809W0656",98.0 } ;
cout
<< "姓名:" << id
[0].name
<< endl
<< "学号:" << id
[0].Number
<< endl
转载请注明原文地址:https://ipadbbs.8miu.com/read-1686.html