В настоящее время я учусь анализировать файл, содержащий некоторые данные об оценках учащегося.
std::ifstream f;
int main()
{
//std::ifstream f;
parse_store(f, "student_grades.txt"); //this line is throwing the error
//keep the window from shutting down
system("pause");
return 0;
}
Функция parse_store
анализирует txt-файл, разбивает каждую строку данных, а затем отправляет вектор tokenized
(выглядит как этот ["Hello", "World"]) в класс, который сохраняется в массиве Объекты класса.
для контекста:
//parses the file returning a vector of student objects
std::vector<Student> parse_store(std::ifstream file, std::string file_name) {
//array of objects
std::vector<Student> student_info;
//create string to store the raw lines
std::string line;
// the delimiter
std::string delimiter = " ";
//open te file
file.open(file_name);
//create vector to hold the tokenized list
std::vector<std::string> tokenized;
//index
int index = 0;
while (file) {
//keep track of the index
index++;
//create a vector to hold each student's grades (will hold the objects)
std::vector<std::vector<std::string>> grades = {};
//read a line from file
std::getline(file, line);
//delimit the line and send it to the constructor
tokenized = delimitMain(line, delimiter);
student_info.push_back(Student(tokenized, index));
}
file.close();
return student_info;
}
Почему строка выше выдает ошибку? Есть ли проблемы с тем, как я помещаю объект файла в вектор, а затем возвращаю его?