Thread: !f.eof error

  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
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    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
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

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