weird compiler error with .eof()

This is a discussion on weird compiler error with .eof() within the C++ Programming forums, part of the General Programming Boards category; Code: void Phonebook::GetEntries(fstream *fFile) { int i=0; if(*fFile.eof()) { return; } else { while(getline(*fFile,vEntries[i].name,'\t') != NULL) { vEntries[i].ordernum=i+1; getline(*fFile,vEntries[i].cnumber,'t'); getline(*fFile,vEntries[i].hnumber,'t'); ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    76

    weird compiler error with .eof()

    Code:
    void Phonebook::GetEntries(fstream *fFile)
    {
         int i=0;
         if(*fFile.eof())
         {
                        return;
         }
         else
         {
             while(getline(*fFile,vEntries[i].name,'\t') != NULL)
             {
                       vEntries[i].ordernum=i+1;
                       getline(*fFile,vEntries[i].cnumber,'t');
                       getline(*fFile,vEntries[i].hnumber,'t');
                       getline(*fFile,vEntries[i].address,'\n');
                       ++i;
             }
         }
    }
    Code:
     C:\Dev-Cpp\My Stuff\C++\PhoneBook\PhoneBook4\main.cpp In member function `void Phonebook::GetEntries(std::fstream*)': 
    347 C:\Dev-Cpp\My Stuff\C++\PhoneBook\PhoneBook4\main.cpp `eof' has not been declared 
    347 C:\Dev-Cpp\My Stuff\C++\PhoneBook\PhoneBook4\main.cpp request for member of non-aggregate type before '(' token

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,062
    I'm guessing you've never worked with pointers to objects.

    You don't deference them, you call their methods with the '->' operator, not the '.' operator.
    Code:
    if(fFile->eof()) return;
    In any event, don't control your loop with eof() control it with the object itself. And also, I'm not really sure about the pointer to a fstream is a good idea either. You should really be passing constant references.
    Code:
    void Phonebook::GetEntries(const fstream &fFile)
    Then ofcourse with that, you just use the '.' operator.
    Last edited by SlyMaelstrom; 05-14-2006 at 04:32 PM.
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    76
    well my reason for calling .eof() is cause i want to check if the file is empty... and if it is return from the function and then continue letting the user enter entries until the file has something in it to display....

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    If the file is empty, the call to getline will fail and the function will return anyway. It seems as if your special case is superfluous.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Have you ever written a compiler?
    By ammar in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 12-27-2004, 06:10 AM
  2. Dev C++ Compiler, Indentation?
    By Zeusbwr in forum C++ Programming
    Replies: 3
    Last Post: 10-21-2004, 06:13 AM
  3. lcc win32 compiler download problems
    By GanglyLamb in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 08-01-2004, 07:39 PM
  4. Borland's compiler is... weird
    By Yoshi in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 11-18-2002, 08:12 PM
  5. Special Compiler for win app's
    By Unregistered in forum Windows Programming
    Replies: 19
    Last Post: 04-26-2002, 03:52 PM

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