lundi 28 septembre 2020

Reading from a file and into a dynamically allocated array of type Student in C++

So this is an assignment revolving around fstreams and struct's, I have a decent understanding of fstreams and struct's (I thought), but for some reason I can't figure out what's wrong with my code. The file I'm reading from starts with an integer 'n' that represents the amount of students in the file, it's then used as the size of the dynamically allocated array of Students.

I go on to read each name, major, and grade from the file into the array of type Student. But for whatever reason it's only reading the first "line" in the file (as in it reads the first name, major, and grade), and does that n times. I messed around with the code and I believe I've narrowed the problem down to the array not actually being of size n. It correctly reads the first int in the file as I've printed it out to make sure that's working, and I've tried manually reading in each Student for the array from the file with the same issues.

This is an assignment so I'm not looking for any straight forward answer, but a nudge in the right direction would be incredibly helpful. Thanks in advance!

Here's a link to my code, and also the input file I'm reading from.

Aucun commentaire:

Enregistrer un commentaire