!f.eof error

This is a discussion on !f.eof error within the C++ Programming forums, part of the General Programming Boards category; Hey folks, I have to read a .dat file with f.eof till the end of it but my Dev C++ ...

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    12

    !f.eof error

    Hey folks,

    I have to read a .dat file with f.eof till the end of it but my Dev C++ writes an error,

    "f undeclared (first use this function)"

    and I dunno what to do.

    [edit]I have already written "use namespace std;" at the beginning of my .cpp file[edit]

    Code:
    while (!f.eof())
            {
            f.getline(cstring, sizeof(cstring));
            textprintf_ex(screen,font,100,m,makecol(255,255, 255), -1,"%s", cstring);
            m=m+20;
            }

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,629
    Find the line that says something to the effect of "fstream f;"
    If you can't find it, that is your problem.

    If you can find it, it is out of scope by the time you get to this loop, so open a file right before the loop.

    Read this: SourceForge.net: Feof - cpwiki

  3. #3
    Registered User
    Join Date
    Jun 2012
    Posts
    12
    Hmm, doesn't work really.

    Code:
    fstream datfile;
            datfile.open("highscore.dat", std::ios_base::in);
            while (!f.eof())
            {
            f.getline(cstring, sizeof(cstring));
            textprintf_ex(screen,font,100,m,makecol(255,255, 255), -1,"%s", cstring);
            m=m+20;
            }

  4. #4
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,629
    Do you realize the variable needs to have the name of "f"?

  5. #5
    Registered User
    Join Date
    Jun 2012
    Posts
    12
    Thank you spiderbro, we're dumb

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    Please help me with input errors.
    We did the while(eof()) sketch last time you asked.
    Apparently, it didn't sink in.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 11-28-2011, 10:48 AM
  2. Replies: 4
    Last Post: 07-24-2011, 09:38 PM
  3. Replies: 1
    Last Post: 11-15-2010, 10:14 AM
  4. Replies: 3
    Last Post: 10-02-2007, 09:12 PM
  5. Replies: 1
    Last Post: 01-11-2007, 04:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21