reading data from file

in my program ive hard coded the number of students from the file but im not suppost to do that. how would i go about doing it with out counting manually?

1
2
3
4
5
6
  int main()
{
    const int STUDENTS=642;
    int scores[STUDENTS];
    ifstream fin("scores2.dat");
        
you could just do something like:

1
2
3
4
5
6
int i = 0;

while(fin){
fin >> scores[i];
i++; 
}


it will need tweaking of course, but that should put you on the right track
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 int main()

{int i=0;
	
     int STUDENTS=i;
    int scores[i];
    ifstream fin("scores2.dat");
    double avg;
    int minScore,maxScore;
    int counts[4]={0};
	{
	

while(fin){
fin >> STUDENTS[i];
i++; 
}
Topic archived. No new replies allowed.