Managing an Array of Students.
I am in the process pulling data from a file. The data contains lines of Students and their info. Example of one line:
Elmore Dennis 78 MED23332
So basically, its last name, first name, his exam score, his gender, his initials, and his ID number. There are about 20 lines of this. I want to put them in an array, and do a bunch of stuff with it. So my first step....I just want to create my array and output it to my own brand new file. Here is the code I have so far:
Code:
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <string.h>
#include <ctype.h>
ofstream outfile;
ifstream infile;
struct studentrec
{
char name[21];
int exam;
char gender;
char id[8];
};
int main()
{
infile.open("rh1165.dat");
outfile.open("out6.txt");
outfile.setf(ios::fixed,ios::floatfield);
outfile.setf(ios::showpoint);
outfile<<setprecision(2);
studentrec student[40];
int count = 0;
infile.getline(student[count].name, 20);
while(infile)
{
infile>>student[count].exam>>student[count].gender;
infile.getline(student[count].id, 7);
count++;
infile.getline(student[count].name, 20);
}
outfile<<studentrec;
return 0;
}
At the end of the program, I just stuck the "outfile<<studentrec;" in for kicks, which resulted in an error. I'm very new at this stuff and what I have even confuses me. Any help appreciated :) Thanks!