Using fstream to fill a struct

closed account (iw75izwU)
I am creating a program that collects a class of max 30 students using a file. Each student has a ID code, 2 test scores and 7 homework assignments. The problem that I am stuck at is when I try to store the datafiles information into the struct, I get a error for the ">>". The ID one is fine but the two within the for loops are the ones giving me the error.

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
 #include <fstream>
#include <conio.h>
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;

int const NUM_OF_STUDENTS = 30;
//int const NUM_OF_TESTS = 2;
//int const NUM_OF_HW = 7;

struct StudentGrade
{
	char ID[9];
	int test_score[2];
	int hw_score[7];
	double test_average;
	double hw_average;
	double final_score;
	char letter_grade;
};

int GetInput(struct StudentGrade List[], int max);


int main()
{
	StudentGrade StudentList[NUM_OF_STUDENTS];
	GetInput(StudentList, NUM_OF_STUDENTS);

}

int GetInput(StudentGrade List[], int max)
{
	fstream datafile;
	datafile.open("prg5data.txt");

	if (!datafile)
	{
		cout << "Error:: Could Not Run! Error::" << endl;
		_getch();
		return(1);
	}

	for (int i = 0; i < max; i++)
	{


		datafile >> List[i].ID;


		for (int i = 0; i < 2; i++)
		{
			datafile >> List[i].test_score;
		}


		for (int i = 0; i < 7; i++)
		{
			datafile >> List[i].hw_score;
		}


	}

}
Topic archived. No new replies allowed.