18-21行和24行报错原因

报错原因是什么 不是定义了struct student吗
后面《报错是为什么呢

img

18-21是不是引号是中文打出来。如果不是先把中文替换为英文试试
24 是arr[i] 是个结构体,你没有重载函数是打不出来的 用arr[i].name 每个字段单独打印

你是不是用的中文逗号,改成英文的。然后cout也不能直接输出一个结构体。要么写一个输出结构体每个成员变量的函数然后调用,要么重载<<。

可参考:

#include<iostream>
#include<string>
using namespace std;
struct Student
{
    string name;
    int age;
    int score;
};
int main()
{
    struct Student arr[3]=
    {
        {"张之",20,80},
        {"李四",30,40},
        {"王五",18,100}
    };
    for (int i=0;i<3;i++)
        cout<<arr[i].name<<" "<<arr[i].age<<" "<<arr[i].score<<" "<<endl;
    system("pause");
    return 0;
}

img