URGENT Help Please, input file not closing

Can anyone help? It's not closing the file when I'm reading in a file. I'm using a Linked List implementation where list.Insert(temp) is a function to add that Student to the list.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int ProcessFile(List &list){
   int j = 0;
   Student temp;
   ifstream infile;
   infile.open("ClassRoster.data"); //Open ClassRoster.data
   if (infile.fail()){
      cout<<"Could not read file.\n"; //Display this if file does not open
      exit(1);
   }
   infile>>temp.id; //Read in the first item of ClassRoster.data
   while(!infile.eof())
   {
      getline(infile, temp.Name, '$');
      infile>>temp.managerStat;
      list.Insert(temp);
      j++;
      cout<<j<<endl;     
      infile>>temp.id; //Read in the first item of ClassRoster.data
   }
   infile.close();  //Close file
   return j;
} 


Here's my data file:

1
2
3
4
5
6
7
8
9
//Attendee ID Name Manager
123 Roger_Cromartie$ 0
001 Susan_Call$ 0
405 Louie_Stewe$ 1
1234 Tony_Stewart$ 1
789 Cal_Loup$ 0
45 Ronnie_Guidry$ 1
1000 Chris_Gardner$ 1
1111 Jack_Jill$ 0


If you need to see anymore of the code, just let me know
Last edited on
What makes you think it's not closing the file?
What makes you think it isn't closing the file?
When I run the program, it just reads out an infinite loop of numbers (j) which is from :
cout<<j<<endl;
Nevermind i got it. You cant put comments in a .data file youre reading in
Topic archived. No new replies allowed.