Unconquerable p 2021-11-07 11:51 采纳率: 90.9%
浏览 23
已结题

#c++#报错下附代码以及目的,求解决

上代码:




#include <iostream>
#include <windows.h>
#include <string>
#include <cmath>

using namespace std; 
struct Student{
    string name;
    int age;
    string sex;
} ;
struct Teacher{
    string name;
    int age;
    string sex;
    int teachage;
};
struct defClass{
    string name;
    int grade;
    int cla;
    int wstudents;
    Student studentslist[wstudents];
    int teachers;
    Teacher techerslist[teachers];


};
int main(){
    
    defClass p;
    Student st1={"张三",12,"男"};
    Student st2={"李四",11,"男"};
    p.wstudents=2;
    p.studentslist{st1,st2};
    cout<<p.studentslist[1].age<<endl;
    return 0;
}

报错:

img


程序目的:声明defClass,Student,Teacher变量类型并创建defClass类,输出类中学生信息

  • 写回答

1条回答 默认 最新

  • [PE]经典八炮 2021-11-07 11:56
    关注
    p.studentslist{st1,st2};
    

    这是什么语法?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 11月18日
  • 已采纳回答 11月10日
  • 创建了问题 11月7日

悬赏问题

  • ¥15 无法输出helloworld
  • ¥15 高通uboot 打印ubi init err 22
  • ¥20 PDF元数据中的XMP媒体管理属性
  • ¥15 R语言中lasso回归报错
  • ¥15 网站突然不能访问了,上午还好好的
  • ¥15 有没有dl可以帮弄”我去图书馆”秒选道具和积分
  • ¥15 semrush,SEO,内嵌网站,api
  • ¥15 Stata:为什么reghdfe后的因变量没有被发现识别啊
  • ¥15 振荡电路,ADS仿真
  • ¥15 关于#c语言#的问题,请各位专家解答!