【发布时间】:2020-10-06 10:44:47
【问题描述】:
我经常遇到这个问题 我已将 cours 类定义为学生类中的对象,现在我无法将其保存在数组中
Screenshot of error as presented by IDE
list<student> listStudents;
FILE* f;
f= fopen("s.t.h.txt", "r");
for (int i=0;i<cont;i++)
{
string arr[4];
fscanf(f, "%d %s %s ", &arr);
student st1;
st1.stu_id = stoi(arr[0]);
st1.stu_name = arr[1];
st1.co_num = stoi(arr[2]);
st1.co = arr[3];
listStudents.push_back(st1);
};
class student {
public:
int stu_id;
string stu_name;
int co_num;
course* co;
int s;
student(int s);
int max = 5;}
【问题讨论】:
-
为什么不能保存在数组中?请解释您的问题
-
你得到什么错误?
-
std::string作为参数传递给fscanf?嗯,这是一个想法。 -
另一件事你的问题不是你不能将学生存储在列表中。问题之一是这一行
st1.co = arr[3];你不能只说std::string现在是course你必须以某种方式转换它