Thread: ARGH! fstream errors

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    26

    ARGH! fstream errors

    I keep getting "expression must be integral or enum data type" on the fstreams in this code . I'm guessing its something with the way I'm handling wiritng to the binary file (I'm having to use an OLD unix compiler for this class so bear in mind its old non standard stuff)

    Code:
    #include <fstream.h>
    #include <ctype.h>
    
      struct employee
       {
       char id[3],
            fname[10],
            lname[10],
            salary[10];
       };
    
    int main (void)
    {
    
      fstream fin,
              foutbad,
              foutgood;  
           
      fin.open("hwk07.txt", ios::in);
      foutgood.open("hwk07.bin", ios::out);
      foutbad.open("errorlog.txt", ios::out);
      
      void readfile (fstream&, fstream&, fstream&);
    
      
      readfile (fstream& fin, fstream& foutgood, fstream& foutbad);
    
      return 0;
    } // main
    
    
    // *** readfile ***
    void readfile (fstream& fin, fstream& foutgood, fstream& foutbad)
    {
      employee goodemployee[100],
               bademployee[100],
               temp;
      
      int goodcounter = 0,
          badcounter = 0,
          i;
      
          
      bool checkresult,
           checkdata (employee&);   
    
      void writefiles (fstream&, employee&);
        
      while (fin >> temp.id)
       {
        fin >> temp.fname >> temp.lname >> temp.salary;
        checkresult = checkdata(employee& temp);
        
        if (checkresult)
         {
          goodemployee[goodcounter] = temp;
          goodcounter++;
         } // if
        
        else
         {
          bademployee[badcounter] = temp;
          badcounter++;
         } // else
       } // while
    
      if (badcounter != 0)
       {
        cout << "File contained " << badcounter << "erroneous record(s).";
       } // if
       
      for (i = 0; i <= goodcounter && goodcounter > 0; i++)
       {
        if (goodemployee[i].id > goodemployee[i+1].id)
         {
          temp = goodemployee[i+1];
          goodemployee[i+1] = goodemployee[i];
          goodemployee[i] = temp;
         } // if
       } // for
    
      writefiles (fstream& foutgood, employee& goodemployee);
      writefiles (fstream& foutbad, employee& bademployee);
    
    } // readfile
    
    // *** checkdata ***
    bool checkdata (employee& temp)
    {
      bool result = true;
      int i;
      
      for (i = 0; i < 4 && result == true; i++)
       {
        if (isalpha(temp.id[i]) == true )
         result = false;
        if (ispunct(temp.id[i]) == true )
         result = false;
       } // for
       
      for (i = 0; i < 10 && result == true; i++)
       {
        if (isalpha(temp.salary[i]) == true )
         result = false;
       } // for
      return result;
    } // checkdata
    
    // *** writefiles ***
    void writefiles (fstream& fout, employee& data)
    {
      fout << "Programmed by:\nAaron Friedley\nChris Reynolds\nLena King\n\n"
           << "\tSalary Data\n ID      Name      Salary";
    
      fout << data.id << "    " << data.fname << ", " << data.lname << "    "
           << data.salary;
    }

  2. #2
    Registered User
    Join Date
    Apr 2004
    Posts
    16
    I don't know if this will help much, but I don't think you need to have the .h in #include <fstream.h>. I think that #include <fstream> works just as well.

  3. #3
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    dude you prototyped your functions inside your main function....no matter how old your compiler is and how non-standard it is, i know it will hate you for that....take those function prototypes out of the main function and put them before the main function.
    My Website

    "Circular logic is good because it is."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  2. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  3. Are fstream and ofstream incompatible?
    By johnnyd in forum C++ Programming
    Replies: 5
    Last Post: 03-19-2003, 12:21 PM
  4. Problems with fstreams.
    By mosdef in forum C++ Programming
    Replies: 7
    Last Post: 06-19-2002, 03:36 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 06:51 PM