Hi guys...
I am working with a struct for the first time and having trouble just loading my data (from an external file into it).
Can someone take apeek at my Load function and tell me what the outline to load should look like?
I have an ex file that has
first names
last names
4 exam grades
Here's ehat I have so far:
Code:#include<iostream> #include<iomanip> #include<fstream> using namespace std; struct Student{ char lastname[20]; char firstname[20]; double exams[4]; double average; char letgrade; bool passed;}; const int MAXSTUDENTS = 25; Student ClassList[MAXSTUDENTS]; //function Prototypes void Load(Student[], int&); void setupFiles(); ifstream infile("C:\\My Documents\\Cee_\\HW\\HW_Final\\IFF.txt"); ofstream outfile("C:\\My Documents\\Cee_\\HW\\HW_Final\\OFF.txt"); int main() { int ns = 0; //calls setupFiles(); Load(ClassList, ns); infile.close(); outfile.close(); return 0; } //set up files fx=========================================== void setupFiles() { if(!infile){ cerr << "Cannot open input file" << endl; } //if if(!outfile){ cerr << "Cannot open output file" << endl; } //if } //Function Load void Load(Student CL[], int& ns) { int y =0; while (infile >> CL[ns].lastname){ (CL[ns].firstname); while (y = 0; y < 4; y ++){ (CL[ns].exams[y]); ns++; }//while1 }//while2 }



LinkBack URL
About LinkBacks


