I'm trying to save and load a class Student
using binary files. This is how the classes are:
class Student{
char name[100];
int regno;
vector<Subjects> subjects;
};
class Subjects{
char initial;
int id;
};
I'm saving and loading this way:
void saveFile(){
fstream f1;
f1.open("data.bin", ios::out | ios::binary);
f1.write((char*)&student, sizeof(Student));
f1.close();
}
void loadFile(){
fstream f1;
f1.open("data.bin", ios::in | ios::binary);
f1.read((char*)&student, sizeof(Student));
f1.close();
}
Nothing fancy as you can see with the saving and loading, but I tested this through print statements, and it's the vector component causing a crash when running it in the terminal (cmd.exe)
.