Reading from a file problems.

So im using getline and reading from a file, and it was working at first now im getting a weird error. If anyone can help me out that would be awesome... i cant seem to find out what went wrong. Here is the code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>  // sort function
#include <fstream>
#include <sstream>
#include "Student.h"
#include "Grade.h"
using namespace std;

int main(int argc, char* argv[])
{
  string line;
  string id;
  string name;
  string address;
  string phone;
  string course;
  string score;
  double total;
  double average;
  int count;
  bool verify = false;

  vector<Student> list;
  vector<Grade> list2;

  ifstream in;
  in.open(argv[1]);

  while (!in.eof()) 
  {
	getline(in, id, '\n');
        getline(in, name, '\n');
        getline(in, address, '\n');
        getline(in, phone, '\n');
  
        Student newStudent(id, name, address, phone);
        list.push_back(newStudent);
		
			
   }
  
  in.close();

  sort(list.begin(),list.end());

  for (int i = 0; i < list.size(); i++)
  {
	  cout << list[i].toString() << endl;
  }



and it ouputs to
1
2
3
4
5
6
7
8
9
10
11
12
Harry C. Anderson

635 Main Drive, Midville, California 48444
(660) 050-2200
Dick B. Smith
529173860
879 Maple Road, Centralia, Colorado 24222
(312) 000-1000
Harry C. Anderson
925173870
635 Main Drive, Midville, California 48444
(660) 050-2200


So basically its reading the last person first and outputting it weird when i just need it to read the lines and store the info and its making everything else go wrong. Please HELP!
Seems like the problem might be in your input file, not your code.
Topic archived. No new replies allowed.