iostream/fstream problem [modified]
-
I'm trying to load a disk file into memory and the program crashes when it tries to exit. As far as I can tell the file never got loaded. The compiler dosen't catch the error, but the debugger did point to this part of ios.cpp when it crashed, the line has a smilie next to it:
ios_base::~ios_base() { // destroy the object if (0 < _Stdstr && 0 < --stdopens[_Stdstr]):mad: return; _Tidy(); _DELETE_CRT(_Ploc); }
My specification file code:#include "DnD_Common_Defs.h" #include "windows.h" #include #include #include using namespace std; class DataLoading { public: DataLoading(); //default constructor RaceDataType ReturnRaceData(int RaceToReturn); protected: bool LoadUpRaceData(string FileName); //loads race data from file private: int NumBaseRaces; ifstream inData; //input file stream RaceDataType BaseRaces[6]; };
Relevant parts of implementation file code:#include #include #include #include #include "Data_Loading_Class.h" #include "DnD_Common_Defs.h" using namespace std; DataLoading::DataLoading() { bool LoadedSuccessfully = false; const string RaceDataFileName = "RaceData.dat"; NumBaseRaces = 7; LoadedSuccessfully = LoadUpRaceData(RaceDataFileName); } bool DataLoading::LoadUpRaceData(string FileName) { bool NoError = true; inData.open(FileName.c_str()); //open up file stream for(int i=-1; i<(NumBaseRaces-1); i++) { inData.ignore(30, ':'); inData>>BaseRaces[i].RaceName; inData.ignore(30, ':'); inData>>BaseRaces[i].ScoreAdjustments.STRadj; inData.ignore(30, ':'); inData>>BaseRaces[i].ScoreAdjustments.DEXadj; inData.ignore(30, ':'); inData>>BaseRaces[i].ScoreAdjustments.CONadj; inData.ignore(30, ':'); inData>>BaseRaces[i].ScoreAdjustments.INTadj; inData.ignore(30, ':'); inData>>BaseRaces[i].ScoreAdjustments.WISadj; inData.ignore(30, ':'); inData>>BaseRaces[i].ScoreAdjustments.CHAadj; } if(inData) NoError = true; else NoError = false; inData.close(); //close file stream return NoError; }
Thanks in advance. :) -- modified at 14:48 Tuesday 18th July, 2006 -
I'm trying to load a disk file into memory and the program crashes when it tries to exit. As far as I can tell the file never got loaded. The compiler dosen't catch the error, but the debugger did point to this part of ios.cpp when it crashed, the line has a smilie next to it:
ios_base::~ios_base() { // destroy the object if (0 < _Stdstr && 0 < --stdopens[_Stdstr]):mad: return; _Tidy(); _DELETE_CRT(_Ploc); }
My specification file code:#include "DnD_Common_Defs.h" #include "windows.h" #include #include #include using namespace std; class DataLoading { public: DataLoading(); //default constructor RaceDataType ReturnRaceData(int RaceToReturn); protected: bool LoadUpRaceData(string FileName); //loads race data from file private: int NumBaseRaces; ifstream inData; //input file stream RaceDataType BaseRaces[6]; };
Relevant parts of implementation file code:#include #include #include #include #include "Data_Loading_Class.h" #include "DnD_Common_Defs.h" using namespace std; DataLoading::DataLoading() { bool LoadedSuccessfully = false; const string RaceDataFileName = "RaceData.dat"; NumBaseRaces = 7; LoadedSuccessfully = LoadUpRaceData(RaceDataFileName); } bool DataLoading::LoadUpRaceData(string FileName) { bool NoError = true; inData.open(FileName.c_str()); //open up file stream for(int i=-1; i<(NumBaseRaces-1); i++) { inData.ignore(30, ':'); inData>>BaseRaces[i].RaceName; inData.ignore(30, ':'); inData>>BaseRaces[i].ScoreAdjustments.STRadj; inData.ignore(30, ':'); inData>>BaseRaces[i].ScoreAdjustments.DEXadj; inData.ignore(30, ':'); inData>>BaseRaces[i].ScoreAdjustments.CONadj; inData.ignore(30, ':'); inData>>BaseRaces[i].ScoreAdjustments.INTadj; inData.ignore(30, ':'); inData>>BaseRaces[i].ScoreAdjustments.WISadj; inData.ignore(30, ':'); inData>>BaseRaces[i].ScoreAdjustments.CHAadj; } if(inData) NoError = true; else NoError = false; inData.close(); //close file stream return NoError; }
Thanks in advance. :) -- modified at 14:48 Tuesday 18th July, 2006