class Student
{
public:
Student()
{
number = 0;
name = newchar[30];
mid1 = 0;
mid2 = 0;
lab = 0.0;
final = 0;
}
int number;
char* name;
int mid1;
int mid2;
double lab;
int final;
};
Until, I exit the program, it does not give any error and run truthfully. I can write or read any records. However, when I exit and run it again and read records, names is read as <BadPtr>. But other fields in the structure be correct.
When you are pulling data from the file are you perhaps pulling more than 29 characters for name? Remember to allocated space for the full amount of characters + the null terminator.
Are you sure the file com252list.dat exist? I think you have to pass ios::app or ios::trunc to fstream if you want it to create the file if it doesn't exist.
name is just a pointer so you are only storing the pointer in the file, and not the actual data. You need to handle the reading and writing of name separately.