问题1:
结构体初始化报错:
#includeusing namespace std; const int STRSIZE = 30; struct bop { char fullname[STRSIZE]; char title[STRSIZE]; char bopname[STRSIZE]; int prefeeence; }; int main() { //以下这么写,报错 bop Bop[5]; Bop[0] = {"Wimp Macho", "JJ", "1", 0}; Bop[1] = {"Raki Rhode", "Junior Progreamer", "2", 1}; Bop[2] = {"Celia Laiter", "MISP", "3", 1}; Bop[3] = {"Hoppy Hipman", "Analyst Trainee", "4", 1}; Bop[4] = {"Pat Hand", "LOOPY", "5", 1}; return 0; }
正确写法
书上写,必须在定义时初始化(记住)
#includeusing namespace std; const int STRSIZE = 30; struct bop { char fullname[STRSIZE]; char title[STRSIZE]; char bopname[STRSIZE]; int prefeeence; }; int main() { bop Bop[5] = { {"Wimp Macho", "JJ", "1", 0}, {"Raki Rhode", "Junior Progreamer", "2", 1}, {"Celia Laiter", "MISP", "3", 1}, {"Hoppy Hipman", "Analyst Trainee", "4", 1}, {"Pat Hand", "LOOPY", "5", 1} }; return 0; }



