C++ file problems

Discussion in 'C++' started by Pete, Mar 26, 2006.

  1. Pete

    Pete Guest

    Hi there all you clever clever programmers.
    I am a university student who's currently face deep in a group project
    to create a program to control and display information from our flight
    simulator. I am personally am in charge of drawing the pretty maps of
    aircraft position, runway position etc.

    Now over this weekend I have been coding my little heart out making a
    lovely section of code that reads in various data from 2 files, one to
    do with navigation beacons and one to do with runways.
    But i have hit a stumbling block, my seperate functions to read in the
    data from each file work perfectly : ON THEIR OWN. For some reason when
    i run one of these functions (both of which use an 'ifstream' object
    called 'infile' ; start with 'infile.open("beacons.txt");' and end with
    'infile.close();') before the other the second time i try to use
    infile.open it ends up lumping me with a get()pointer position of '-1'
    ! Does anyone have any clues why?
     
    Pete, Mar 26, 2006
    #1
    1. Advertising

  2. Pete

    Rolf Magnus Guest

    Pete wrote:

    > Hi there all you clever clever programmers.
    > I am a university student who's currently face deep in a group project
    > to create a program to control and display information from our flight
    > simulator. I am personally am in charge of drawing the pretty maps of
    > aircraft position, runway position etc.
    >
    > Now over this weekend I have been coding my little heart out making a
    > lovely section of code that reads in various data from 2 files, one to
    > do with navigation beacons and one to do with runways.
    > But i have hit a stumbling block, my seperate functions to read in the
    > data from each file work perfectly : ON THEIR OWN. For some reason when
    > i run one of these functions (both of which use an 'ifstream' object
    > called 'infile' ; start with 'infile.open("beacons.txt");' and end with
    > 'infile.close();') before the other the second time i try to use
    > infile.open it ends up lumping me with a get()pointer position of '-1'
    > ! Does anyone have any clues why?


    Do both use the same stream object? If yes, you must first reset the
    stream's state, because if it has reached the end of file, your eof bit
    will still be set after closing and re-opening. Alternatively, just use an
    own ifstream for each of your functions.
     
    Rolf Magnus, Mar 26, 2006
    #2
    1. Advertising

  3. Pete

    Moonlit Guest

    Hi,

    I am not completely sure, but I think you probably tried to read past end of
    file in the first one after which the error bit is set.

    Using then the same on the second still leaves the object in an error
    condition. Usually it is nicer to use two different objects.



    Regards, Ron AF Greve

    http://moonlit.xs4all.nl

    "Pete" <> wrote in message
    news:...
    > Hi there all you clever clever programmers.
    > I am a university student who's currently face deep in a group project
    > to create a program to control and display information from our flight
    > simulator. I am personally am in charge of drawing the pretty maps of
    > aircraft position, runway position etc.
    >
    > Now over this weekend I have been coding my little heart out making a
    > lovely section of code that reads in various data from 2 files, one to
    > do with navigation beacons and one to do with runways.
    > But i have hit a stumbling block, my seperate functions to read in the
    > data from each file work perfectly : ON THEIR OWN. For some reason when
    > i run one of these functions (both of which use an 'ifstream' object
    > called 'infile' ; start with 'infile.open("beacons.txt");' and end with
    > 'infile.close();') before the other the second time i try to use
    > infile.open it ends up lumping me with a get()pointer position of '-1'
    > ! Does anyone have any clues why?
    >
     
    Moonlit, Mar 26, 2006
    #3
  4. Pete

    Pete Guest

    Thanks a bunch for your advice.
    Yes both do use the same object and unfortunately both have to use the
    same stream object and unfortunately they have to beacause they both
    share the functions for extracting the names, Latitudes and Longitudes
    of the beacons (i suppose i could seperate them but i like the
    simplicity of the previous method)
     
    Pete, Mar 27, 2006
    #4
  5. Pete

    Rolf Magnus Guest

    Pete wrote:

    > Thanks a bunch for your advice.
    > Yes both do use the same object and unfortunately both have to use the
    > same stream object and unfortunately they have to beacause they both
    > share the functions for extracting the names, Latitudes and Longitudes
    > of the beacons (i suppose i could seperate them but i like the
    > simplicity of the previous method)


    Actually, I'd say it's simpler to create the stream within the function as
    local variable. Anyway, you can reset the stream's state with
    infile.clear().
     
    Rolf Magnus, Mar 27, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HNguyen
    Replies:
    4
    Views:
    2,410
    HNguyen
    Dec 21, 2004
  2. Susan Baker
    Replies:
    2
    Views:
    817
    kelvSYC
    Jun 26, 2005
  3. Shelly

    Problems, problems for newbie

    Shelly, Sep 2, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    2,188
    Shelly
    Sep 3, 2007
  4. Sak Na rede
    Replies:
    0
    Views:
    420
    Sak Na rede
    Jan 30, 2009
  5. DJ Stunks
    Replies:
    1
    Views:
    183
    J. Gleixner
    Jan 23, 2006
Loading...

Share This Page