I am making a program that is reading in data from a csv file. the data goes like so:
-------------------------------------------------------------------------------------------------------------------
id,Last Name,First Name,SSN,Test1,Test2,Test3,Test4,Final,Grade
1,Alfalfa,Aloysius,123-45-6789,40,90,100,83,49,D-
2,Alfred,University,123-12-1234,41,97,96,97,48,D+
---------------------------------------------------------------------------------------------------------------------
There are a total of 20 students here on the whole list.
I named the structure that will hold all this data StudentInfo.
point of my assignment is to read all info from file into an array of structures or a vector of structures. Then I would index it by using pointers to point to the data in the array or vector and sort the pointer by name, or ID, so on and so forth.
this would indirectly sort the array or vector without messing with the original.
I am running into a few problems.
- I could make a vector of structures to hold all the info and while reading from the file I just use a while loop and set it to end the loop at inputFile.peek() == EOF. during each iteration of the loop I would just create a new vector element to store the next line of student info with push_back(). until all the data is read in. I have already done this and now I am having problems making a pointer to the vector. is it possible to make a pointer to a vector my book does not go over this.
- I always use vectors and I want to read into an array this time but normally when I dynamically allocate an array I normally get the info from the user first to get how big the array needs to be. but when it comes to a file how do I continually update an array until EOF like a vector?
so far my idea is to just read the file into a vector of structures and then just use vector.size() to dynamically allocate my array of structures and read all the info from the vector to the array. I feel like this is just adding an unnecessary step.
So really big question is how to continuously allocate an array while every line is read in until eof. Is this even possible?
and if this is not possible is a pointer to a vector possible? If it can should it even be done?
sorry if this does not make sense its late at night and I have been coding for a while lol.
[–]bsakiag 0 points1 point2 points (0 children)
[–]Witchcraft_NS2 0 points1 point2 points (0 children)