Reading from file to vectors (warning, grammer fail)

Hello all,

So...here we go.

I have a text file that that looks a lot like this:

FirstName LastName SID
Quiz1 Quiz2 Quiz3...Quiz6
HW1...HW10
Test1...Test4

it repeats for the next student up to 20 students. There would be an EOF in between each student record to kick out to the menu and read the next student. (in theory anyway)

The program will take the numeric data (quiz, hw, test scores) and computes the final score and final grade. It will also give the highest score from the group of students in the text file.

The way I want to do it is read the first line in to vector<student> and the remaining lines in to vector<int> quizzes, hw, tests then perform my calculations on the elements in those last three vectors. Then take those final scores and read them each to a vector<groupofstudents> then sort the vector and cout the first/last (highest) element. No problem right? Wrong.

Nothing is working right. I am having a real serious problem reading from the file. Reading one line is fine. Several? I have problems.

Should be something like this:

for (i = 0, vector.size() < i, i++) ist>>vector.push_back() etc until there are no more elements in that line...

Well, that hasn't worked. what I was thinking was putting an EOF character '*' at the end of each line to signal the program to move to the next line and read to a new vector.

ALso, yes, this is a class project. I'm not looking for someone to write my program, I just need someone to evaluate my logic. Amidoinitrite.jpg

also, inb4 "we'd like to see your code." I need to make sure I cna post snippets of it w/o jeopardizing my grade in teh class.

(can I type or what! no spell check for me!)

-kickasstimus


Do something like this:
1
2
3
4
5
6
7
8
std::vector<std::string> v;
while(ist.good())
{
  std::string str;
  std::getline(ist, str);
  if(ist.good())
    v.push_back(str);
}
Topic archived. No new replies allowed.