gpt4 book ai didi

c++ - 为什么结构类型的数组不能正常工作?

转载 作者:行者123 更新时间:2023-11-28 02:26:23 25 4
gpt4 key购买 nike

<分区>

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
struct data
{
string country;
string fathername;
int age;
};
data NAME;

data name[5]={"Ali", "Usman", "Sarmad", "Awais", "Junaid"};
name[0]=(struct data){"Saudi Arabia","Tahir Awan",24};
name[1]=(struct data){"England","Akram Khan",20};
name[2]=(struct data){"China","Amjad Ali",20};
name[3]=(struct data){"Syria","Ahmad Ali",19};
name[4]=(struct data){"Oman","Zohaib Sultan",24};

cout << "Enter Name of student/n";
cin >> NAME;

int j;
for(int i=0; i<6; i++)
{
if(NAME==name[i])
j=i;
}
cout << "We have following data for " << name[j]<< endl;
cout << "Country: " << name[j].country << endl << "Father name: " << name[j].fathername << endl << "Age: " << name[j].age << endl;

return 0;

}

它给了我数组初始化错误以及更多错误。我尝试了很多来找到错误的原因但找不到。请在你的编译器中编译它并告诉我我可以删除错误。另外请告诉我错误的原因。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com