Hi, I've been confused by this error I encountered. I got a segmentation fault when I tried to close a file stream. The funny thing is if I used getline from the stream, it worked. This is the code:
Can anybody tell me what's the problem? This gave me a headache. If this doesn't work, I'll revert it back to C style file operation. Thanks in advance.Code:include <fstream> include <vector> include ..... ....... using namespace std; struct sDemoActInFrame { int frame; //The frame of the action int action; //The action Sint16 cursorX; //Only if action == CURSOR_HAND Sint16 cursorY; //Only if action == CURSOR_HAND }; vector<sDemoActInFrame> mDemoActList; fstream filestr; //File stream char temp[256]; //Temp buffer for reading bool readData=true; //Open filestream filestr.open ("./Stage_01/demo/demoacts.txt", fstream::in); // Begin loading demo action list filestr.getline(temp,256); while (readData) { while (temp[0] == '#' || temp[0] == '\r' || temp[0] == '\0' || temp[0] == '\n' || strlen(temp) == 0) { filestr.getline(temp,256); } if (temp[0]==':') //::end = exit from loop { readData=false; } else { sDemoActInFrame tempDemoAct; sscanf ( temp, " %d : %d : %d : %d ", &(tempDemoAct.frame), &(tempDemoAct.action), &(tempDemoAct.cursorX), &(tempDemoAct.cursorY)); mDemoActList.push_back(tempDemoAct); filestr.getline(temp,256); } } // End loading actions filestr.close(); <-- segmentation error



LinkBack URL
About LinkBacks


