title: Why do I get an error saying eof is not a class type of fstream?
body: <p>I have printed out the array in the main just to test this method works and it does. But when I try to do the same thing in a different class I get errors.  </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;fstream&gt;
  #include "struct.h"
  #include "phoneBook.h"
  
  using namespace std;
  
  int main()
  {
      struct contacts info[256];
      phoneTools manipulate;
      fstream phoneBook ("phoneBook.txt");
  
      if(!phoneBook.is_open())
      {
          cout&lt;&lt; "The file can not be opened";
          cout&lt;&lt; endl;
          cout&lt;&lt; "Terminating!";
  
          exit(1);
      }
  
      else
      {
          //populate array of structs
          int i = 0;
          while(!phoneBook.eof())
          {
              phoneBook&gt;&gt; info[i].firstName;
              phoneBook&gt;&gt; info[i].surName;
              phoneBook&gt;&gt; info[i].phoneNumber;
              phoneBook&gt;&gt; info[i].email;
              phoneBook&gt;&gt; info[i].relationship;
              i++;
          }
      }
  
      manipulate.addContact(info, phoneBook);
  }
  </code></pre>
  
  <p>This is the other class where I get the errors. I will put the headers below, along with the error messages. I also realize I might have some libraries imported that I am not using, but I will. I just have not finished creating all the functions.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;fstream&gt;
  #include "struct.h"
  
  using namespace std;
  
  void writeStructToDatabase(struct contacts writeContact[], fstream *phoneBook)
  {
      //We are passed new array of contacts
      //write this new array to the phonebook file
      int i = 0;
      while(!phoneBook-&gt;eof())
      {
          phoneBook&lt;&lt; writeContact[i].firstName;
          phoneBook&lt;&lt; writeContact[i].surName;
          phoneBook&lt;&lt; writeContact[i].phoneNumber;
          phoneBook&lt;&lt; writeContact[i].email;
          phoneBook&lt;&lt; writeContact[i].relationship;
          i++;
      }
  }
  
  void showPhoneBook(struct contacts print[])
  {
      int num = (sizeof(print) / sizeof(*print));
  
      cout&lt;&lt; endl;
      cout&lt;&lt; endl;
      for(int i = 0; i &lt; num; i++)
      {
          cout&lt;&lt; print[i].firstName;
          cout&lt;&lt; endl;
  
          cout&lt;&lt; print[i].surName;
          cout&lt;&lt; endl;
  
          cout&lt;&lt; print[i].phoneNumber;
          cout&lt;&lt; endl;
  
          cout&lt;&lt; print[i].email;
          cout&lt;&lt; endl;
  
          cout&lt;&lt; print[i].relationship;
          cout&lt;&lt; endl;
      }
      cout&lt;&lt; endl;
  }
  
  void addContact(struct contacts newContact[], fstream *phoneBook)
  {
      int num = (sizeof(newContact) / sizeof(*newContact));
  
      cout&lt;&lt; "First Name: ";
      cin&gt;&gt; newContact[num].firstName;
      cout&lt;&lt; endl;
  
      cout&lt;&lt; "Last Name: ";
      cin&gt;&gt; newContact[num].surName;
      cout&lt;&lt; endl;
  
      cout&lt;&lt; "Phone Number: ";
      cin&gt;&gt; newContact[num].phoneNumber;
      cout&lt;&lt; endl;
  
      cout&lt;&lt; "Email: ";
      cin&gt;&gt; newContact[num].email;
      cout&lt;&lt; endl;
  
      cout&lt;&lt; "Relationship: ";
      cin&gt;&gt; newContact[num].relationship;
      cout&lt;&lt; endl;
  
      writeStructToDatabase(newContact, phoneBook);
  }
  
  void deleteContact(struct contacts delContact[], fstream *phoneBook)
  {
      string first;
      string last;
  
      cout&lt;&lt; "First Name: ";
      cin&gt;&gt; first;
      cout&lt;&lt; endl;
  
      cout&lt;&lt; "Last Name: ";
      cin&gt;&gt; last;
      cout&lt;&lt; endl;
  
      int num = (sizeof(delContact)/sizeof(*delContact));
  
      int exit = 0;
      int i = 0;
      while(exit == 0)
      {
          if((strcmp(delContact[i].firstName, first) == 0) &amp;&amp;
             (strcmp(delContact[i].surName, last) == 0))
          {
              for(int j = i; j &lt; num; j++)
              {
                  delContact[j] = delContact[j+1];
              }
  
              exit = 1;
          }
  
          i++;
      }
  
  writeStructToDatabase(delContact, phoneBook);
  }
  </code></pre>
  
  <p>Here is my header for my struct</p>
  
  <pre><code>#include &lt;string.h&gt;
  
  using namespace std;
  
  #ifndef STRUCT_H
  #define STRUCT_H
  struct contacts
  {
      string firstName;
      string surName;
      string phoneNumber;
      string email;
      string relationship;
  };
  #endif
  </code></pre>
  
  <p>Here is the header for my functions class</p>
  
  <pre><code>#include &lt;fstream&gt;
  
  using namespace std;
  
  #ifndef PHONE_BOOK_H
  #define PHONE_BOOK_H
  
  //enter methods below this line
  //ex. extern void getRandInteger(int max);
  
  class phoneTools
  {
      public:
      void addContact(contacts newContact[], fstream *phoneBook);
      void showPhoneBook(contacts print[]);
      void deleteContact(contacts delContact[], fstream *phoneBook);
  
      private:
      void writeStructToDatabase(contacts writeContact[], fstream *phoneBook);
  };
  
  //enter methods above this line
  
  #endif /* __PHONE_BOOK_H */
  </code></pre>
  
  <p>Now here are the errors I am getting</p>
  
  <pre><code>phoneBook.cpp: In function ‘void writeStructToDatabase(contacts*, std::fstream*)’:
  phoneBook.cpp:16: error: no match for ‘operator&lt;&lt;’ in ‘phoneBook &lt;&lt; writeContact[i].contacts::firstName’
  phoneBook.cpp:17: error: no match for ‘operator&lt;&lt;’ in ‘phoneBook &lt;&lt; writeContact[i].contacts::surName’
  phoneBook.cpp:18: error: no match for ‘operator&lt;&lt;’ in ‘phoneBook &lt;&lt; writeContact[i].contacts::phoneNumber’
  phoneBook.cpp:19: error: no match for ‘operator&lt;&lt;’ in ‘phoneBook &lt;&lt; writeContact[i].contacts::email’
  phoneBook.cpp:20: error: no match for ‘operator&lt;&lt;’ in ‘phoneBook &lt;&lt; writeContact[i].contacts::relationship’
  phoneBook.cpp: In function ‘void deleteContact(contacts*, std::fstream*)’:
  phoneBook.cpp:97: error: cannot convert ‘std::string’ to ‘const char*’ for argument ‘1’ to ‘int strcmp(const char*, const char*)’
  phoneBook.cpp:98: error: cannot convert ‘std::string’ to ‘const char*’ for argument ‘1’ to ‘int strcmp(const char*, const char*)’
  phoneBookDriver.cpp: In function ‘int main()’:
  phoneBookDriver.cpp:40: error: invalid conversion from ‘void*’ to ‘std::fstream*’
  phoneBookDriver.cpp:40: error:   initializing argument 2 of ‘void phoneTools::addContact(contacts*, std::fstream*)’
  i686-apple-darwin11-llvm-g++-4.2: phoneBook.o: No such file or directory
  i686-apple-darwin11-llvm-g++-4.2: phoneBookDriver.o: No such file or directory
  i686-apple-darwin11-llvm-g++-4.2: no input files
  </code></pre>
  
  <p>I have searched for the last day trying to figure out why I am not able to use the fstream functions even though I imported the library, plus I am able to do this in my main. This is my first question here, so I hope I formatted it correctly. Also this is just for fun over the summer. Not homework or anything. </p>