Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. iostream/fstream problem [modified]

iostream/fstream problem [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++iosdebuggingperformance
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CoffeeAddict19
    wrote on last edited by
    #1

    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

    E 1 Reply Last reply
    0
    • C CoffeeAddict19

      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

      E Offline
      E Offline
      earl
      wrote on last edited by
      #2

      which line in your function triggered your error? In the future, please post with pre instead of code; it preserves formatting. earl

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups