I'm having some problems with reading a binary file, I keep getting an unhandled exception in XUtility.h. It reads the first sections of the file fine, but when it goes out of scope it crashes?
Here's my code:
void ViewEnts() {
system("CLS");
cout << "Entity List" << endl;
ifstream file("entities.entl", ios::in | ios::binary);
if(file.is_open()) {
EntityHeader head;
file.read((char*)&head, sizeof(EntityHeader));
for(int x = 0; x != head.num; x++) {
EntityStructure ent;
file.read((char*)&ent, sizeof(EntityStructure));
cout << "Entity " << x << ") " << ent.className << endl;
cout << "Renderable: " << ent.isRenderable << endl;
cout << "Script Location: " << ent.scriptLocation << endl;
system("PAUSE");
} //CRASHES HERE
} else {
cout << "FATAL ERROR OCCURED: COULD NOT OPEN FILE" << endl;
system("PAUSE");
}
file.close();
system("PAUSE");
}
Also if I make "EntityStructure ent;" a global variable it will read the whole file fine until I exit the program which it then will crash?