|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
报了一个错;说main()后面的第一个花括号应改成分号。(这是一个没写完的……)
#include <iostream>
#include <string>
using namespace std;
#include <string>
//1.老师结构体
//2.学生结构体
struct student {
string sname;
int score;
};
struct teacher {
string tname;
student stuarr[5];
};
void a(struct teacher teaarr[], int len) {
string nameseed = "ABCDE";
for (int i = 0; i < len; i++) {
teaarr[i].tname = "teacher_";
teaarr[i].tname += nameseed[i];
for (int j = 0; j < 5; j++)
{
teaarr[i].stuarr[j].sname = "student_";
teaarr[i].stuarr[j].sname += nameseed[j];
}
};
int main(){//学校正在做毕设项目,每个老师带领五个学生,总共有三名老师,需求如下
//设计学生和老师的结构体,其中在老师的结构体中,有老师姓名和和一个存放5名学生的数组作为成员
//学生的成员有姓名,考试分数,创建数组存放3明老师,通过函数给每个老师及所带的学生赋值
//最终打印出老师数据和所带学生数据。
struct teacher teaarr[3];
int len = sizeof(teaarr) / sizeof(teaarr[0]);
a(teaarr, len);
system("pause");
return 0;
}
试试这个吧,有时我写太快偶尔也会漏掉括号,但补回去就没有太大问题了: - #include <iostream>
- #include <string>
- using namespace std;
- // #include <string> <-------------------------------- 这里你多写了一次 --------------------------------
- struct student {
- string sname;
- int score;
- };
- struct teacher {
- string tname;
- student stuarr[5];
- };
- void a(struct teacher teaarr[], int len) {
- string nameseed = "ABCDE";
- for (int i = 0; i < len; i++) {
- teaarr[i].tname = "teacher_";
- teaarr[i].tname += nameseed[i];
- for (int j = 0; j < 5; j++)
- {
- teaarr[i].stuarr[j].sname = "student_";
- teaarr[i].stuarr[j].sname += nameseed[j];
- }
- } // <-------------------------------- 这里少了个花号 --------------------------------
- } // <-------------------------------- 这里不用分号 --------------------------------
- int main(){
- struct teacher teaarr[3];
- int len = sizeof(teaarr) / sizeof(teaarr[0]);
- a(teaarr, len);
- system("pause");
- return 0;
- }
复制代码
|
|