Ok I tried putting in a load/save feature into my program, so I don't have to re-enter all the data over again. So I added the following functions:
Code:
#include <iostream>
#include <stdlib.h>
#include <wincon.h>
#include <conio.h>
#include <windows.h>
#include <fstream>
#include "gkinfo.h"
using namespace std;
void savestats(student &x, course* c)
{
clrscr();
ofstream save;
save.open("stats.dat");
cout<<"Saving statistics...";
save.open("stats.dat");
int i;
/*Save variables*/
save<<x.FNAME<<endl; //Firstname
save<<x.LNAME<<endl; //Lastname
save<<x.ID<<endl; //Student ID
/*Course variable save*/
for(i=1; i<25; i++)
{
save<<c[i].cGrade<<endl; //Grade
save<<c[i].CourseName<<endl; //Course Name
save<<c[i].nCurrentPoints<<endl; //Current poits in class
save<<c[i].nMaxPoints<<endl; //Max points you got
save<<c[i].nHour<<endl; //Hour of class
}
save.close(); //close the file
cout<<"Stats saved!";
}
void loadstats(student &x, course* c)
{
clrscr();
ifstream load;
load.open("stats.dat");
cout<<"Loading statistics...";
int j;
/* load vars*/
load>>x.FNAME; //First Name
cout<<x.FNAME;
load>>x.LNAME; //LastName
load>>x.ID; //ID
for (j=1; j<25; j++)
{
load>>c[j].cGrade;
load>>c[j].CourseName;
load>>c[j].nCurrentPoints;
load>>c[j].nMaxPoints;
load>>c[j].nHour;
}
load.close();
cout<<"Stats opened!";
cin.get();
}
Now the problem is, when I have it spit out the variable x.FNAME, it spits out the name of the variable I entered after I had saved. So say I had saved it when x.FNAME==BFGH. Ok, so then after saving I'll make a new name, and set x.FNAME==HGFB. Well when I load the file, x.FNAME still equals HGFB, and not BFGH like I had it saved to. I don't understand why it is doing this. I thought that the ifstream opened up for loading the variables? Does anybody know why it is doing this?
*NOTE: Sorry for asking so many questions *
EDIT: I'm such an idiot, I had save.open() twice, causing the error. Let that be a lesson to everybody: Don't double call