View Single Post
Old 11-14-2004, 01:36 PM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Code:
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <vector>

using namespace std;

struct stud
{
   string lastname;
   string firstname;
   float mid;
   float final;
   vector<double> homework;
};

int main()
{
    ifstream marks("students.txt");
    int tempHW(0);
    stud tempstud;
    vector<stud> class1;
    while (marks >> tempstud.lastname)
    {
        marks >> tempstud.firstname;
        marks >> tempstud.mid;
        marks >> tempstud.final;
        marks >> tempHW;
        
        while (tempHW != -1)
        {
           tempstud.homework.push_back(tempHW);
           marks >> tempHW;
        }
        
        class1.push_back(tempstud);
    }

   for(unsigned i=0; i != class1.size(); ++i)
   {
      cout<<class1[i].lastname<<" "<<
      class1[i].firstname<<" "<<
      class1[i].final<<" "<<
      class1[i].mid<<" ";
      for(unsigned j = 0; j != class1[i].homework.size(); ++j)
      {
         cout<<class1[i].homework[j]<<" ";
      }
      cout<<endl;
   }

    system("PAUSE");
    return 0;
}
__________________
Valmont is offline   Reply With Quote