Having Trouble with File I/O

I'm trying to use file I/O for an event structure in my game. The event definitions go like:
::event [number] <[action flag 1] <[action flag 2] >>

My file has:
::event 0000 >>

My code to read it is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void do_event(string filename, int eventindex) { //code for loading events
    ifstream eventfile( filename.c_str(), ios::in | ios::app );
    bool scanning = true;
    eventfile.get( emptyvalue, 8 );
    eventfile.get( tempvalue, 4 );
    while (scanning) {
        if ( atoi(tempvalue) == eventindex ) {
            //the event we're scanning for
            eventfile.get( emptyvalue, 1 );
            eventfile.get( tempvalue, 2 );
            if ( strcmp( tempvalue, ">>" ) == 0 ) { //end of event
                eventfile.close();
                scanning = false;
            }
        }
        else {
            //not the event we're scanning for
            eventfile.getline( emptyvalue, 1 );
            //try the next line
        }
    }
}


This results in a Runtime error. I expect it's because of the loop, but it should close the file and end the loop when it gets to ">>", which I have in the file at the right place.
Last edited on
ifstream eventfile( filename.c_str(), ios::in | ios::app );

You should remove the ios::app flag because that positions the file pointer at the end of the file.
o lol
thanks
Last edited on
Topic archived. No new replies allowed.