So basically, I have no idea. I can't get getline to work for the structure and I've been trying for hours upon hours. I'm also using a function. Any help would be appreciated.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
void studentRegistration(Values info[MAX_STUDENT], int size)
{
ifstream inFile; //needed to open file and read
inFile.open("student.txt");
if (!inFile.fail())
{
for (int i = 0; i < 11; i++)
{
getline(inFile, info[i].ID);
}
inFile.close();
cout << "Done.\n";
}
}
My structure looks like this:
1 2 3 4 5 6
struct Values
{
int ID;
char name;
char answer_choice;
};
You're using getline on an int. You can only use getline on strings. Also you need to read info by info... Your for loop should have at least 3 states, depending on how you program it.
1 2 3 4 5 6
for(int i = 0; i << 1; i++)
{
// read in type_int memberID
// read in name
// read in answer_choice
}
That still leaves room for uncertainty, I can't be sure whether the ID is an integer or maybe contains other characters. name must be a string, not a single character. answer could be anything, an integer, a character, a string of several words.
Given that your struct had char name; which doesn't make sense, it is quite likely that the other parts may be wrong or less than optimal too.
Assuming that only the name is a string, maybe do it like this. Here I read the file one line at a time, then extract the details from that line. A stringstream is used to do that. Also I passed the size by reference, to hold the actual number of records read from the file.