看错误提示是array有歧义,应该是你的变量命名与std命名空间的类型名重名了。
不能用array做变量名
你输出那里不应该换行的。
还有,你好像没写return 0;
我这个是可以输出的
#include <iostream>
#include <string>
using namespace std;
struct student{
string name;
int age;
int score;
};
struct student array[3]=
{
{"小明",18,100},{"小红",19,100},{"小蓝",20,99}
};
int main(){
for (int i=0;i<=2;i++){
cout << "姓名:" << array[i].name << "年龄:" << array[i].age << "分数:" << array[i].score << endl;
}
return 0;
}
供参考:
#include<iostream>
#include<string>
using namespace std;
struct student {
string name;
int age;
int score;
};
int main()
{
struct student array[3] = { {"小梅",18,100},{"泰勒姐姐",19,100},{"泰迪熊",20,99} };
for (int i = 0; i <= 2; i++)
{
cout << "姓名:" << array[i].name << " 年龄:" << array[i].age << " 成绩:" << array[i].score << endl;
}
}