I am having an issue with C++ structures. In my program below, I am trying to read from a file the number of questions to an exam, the answers to the exam, and the file of the student's answers to the exam. That all works, but when I try to put the student's info into an array for a structure, the variable id doesn't work for some reason. The compiler, which is Microsoft Visual Studio 2017 RC, says that "students->id[i]" has an error which says: "expression must have pointer to object type" and I don't know why. I marked where the issue is and took off the rest of the code, all I have is the function calculateGrade being used. I've worked on this for a while now and can't get anywhere without fixing this. Any help is appreciated!
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
struct studentInfo {
int id;
string firstName;
string lastName;
string exam;
};
double calculateGrade(struct studentInfo);
int main() {
const int SIZE = 12;
studentInfo students[SIZE];
string fileName, key, studentFile;
ifstream file, fileForStudents;
int numOfQuestions, i = 0, id;
cout << "Please enter a file name: ";
cin >> fileName;
file.open(fileName);
if (!file.is_open()) {
cout << "Could not open file";
}
file >> numOfQuestions >> key >> studentFile;
fileForStudents.open(studentFile);
if (!fileForStudents.is_open()) {
cout << "Could not open file";
}
while (!fileForStudents.eof()) {
fileForStudents >> id >> students->firstName[i] >> students->lastName[i] >> students->exam[i];
students->id[i] = id; //issue is here
i++;
}
calculateGrade(students[SIZE]);
return 0;
}