binary file beginner

Hi guys, I'm trying to work with a binary file (create, write, read, etc). I can't get past an error on Line 29. "variable or field 'ShowContents' declared void" I'm just starting this, so the rest of the menu options you see are yet to come. I can't get this to even compile yet. Any thoughts?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <cstdlib>
#include <iostream>
#include <string>
#include <iomanip>
#include <istream>
#include <fstream>

const int SIZE_A = 25;        
const int SIZE_B = 8;

typedef char String_A[SIZE_A];         
typedef char String_B[SIZE_B];

struct EmpInfo{
               String_A fullname;
               String_B id;
              };
               
struct PayInfo{
               EmpInfo nameId;
               double rate;
               double gross;
               double statetax;
               double fedtax;
               double net;
              };

int Menu();
void ShowContents(fstream&);
void WriteFile(fstream&,PayInfo[],const int);   


using namespace std;

int main()
{
    char filename[]= "employees.dat";
    const double STATETAX = .05;
    const double FEDTAX = .15;
    const int SIZE = 5;
    PayInfo employee[SIZE];
    char answer,choice;
    
    fstream myFile;
        
    if(myFile.good())
    {
        do
        {
            choice = Menu();
            
            switch(choice)
            {
                 case 1: ShowContents(myFile);
                 case 2: WriteFile(myFile,employee,SIZE)
                 
            }     
        cout << endl;
        }while (choice != 7);
 
    }
	else
         cout << "File did not open successfully." << endl << endl;
 
    cout << endl << endl;
    
    system("PAUSE");
    return EXIT_SUCCESS;

}     

/****************************************************************************
 *
 * Function    :  Menu function asks the user to choose an option.
 *
 * Parameters  :  Nothing 
 *
 * Returns     :  mychoice
 *
 ***************************************************************************/
int Menu()
{
    int mychoice;
    cout << "Choose a menu option: " << endl;
    cout << "1- Display contents of the file\n";
    cout << "2- Enter a new record\n";
    cout << "3- Append a record\n";
    cout << "4- Delete a record\n";
    cout << "5- Search for a record\n";
    cout << "6- Modify a record\n";
    cout << "7- Sort the file\n";
    cout << "8- Wipe out all records\n";
    cout << "9- Exit\n\n";
    cout << "Enter your choice: ";
    cin >> mychoice;
    return mychoice;
}

/****************************************************************************
 *
 * Function    :  ShowContents function that reads data from a file and displays it.
 *
 * Parameters  :
 *          1  :  &inFile  = pointer to file
 *
 * Returns     :  Nothing
 *
 ***************************************************************************/
 
 void ShowContents(fstream &inFile)
 {
        char byte;
        inFile.open("employees.dat");
        inFile.clear();
	
        cout<< "\nReading contents from the file:" <<endl;
        if(inFile)
        {
             inFile.get(byte);
             while(inFile.good())
             {
                  cout << byte;
                  inFile.get(byte);  
             }
         }
         inFile.close();
    

}
At line 33 you have using namespace std;

But a couple of lines earlier you are referring to fstream.
Either explicitly put std::fstream or more simply, move line 33 up before line 27.



ah that worked. thanks Chervil!
Topic archived. No new replies allowed.