dynamic array from an input file

I keep getting the error that incomplete type is not allowed for empData dynamicArray [];

I don't want to set the elements because the first number of the input file sets the elements or the number within the bracket. So how do I rewrite that line so it can read the first number of the that file and set the number of employees from there.

#include <fstream> // for ifstream
#include <iostream> // for cin, cout and cerr
#include <string> // for string datatype
#include <cstdlib> // needed for the exit function
#include <iomanip>
using namespace std;

struct empData
{
int empNumber;
int department;
double payRate;
double hoursWorked;
char exempt;
};

string getInputFileName(); // a function to prompt for the complete
// input file name

string getOutputFileName(); // a function to prompt for the complete
// output file name


int main ()
{
empData dynamicArray [];

ifstream inFile; // Handle for the input file

string inputfileName; // complete file name include the path

inputfileName = getInputFileName(); // prompt and obtain the full file
// name

inFile.open(inputfileName.c_str()); // try to open the file

if (!inFile.is_open()) // test for unsuccessful file opening
{
cerr << "Cannot open file: " << inputfileName << endl << endl;
exit (0);
}

for (int index = 0; index < 4; index++)
{
inFile >> dynamicArray[index].empNumber >> dynamicArray[index].department >>
dynamicArray[index].payRate >> dynamicArray[index].hoursWorked >>
dynamicArray[index].exempt;
}

double basePay;

for (int index = 0; index < 4; index++)
{
basePay = dynamicArray[index].payRate * dynamicArray[index].hoursWorked;
}

double Overtime;

for (int index = 0; index < 4; index++)
{
for (int count = 0; count > 40 || count < dynamicArray[index].hoursWorked; count++)
{
Overtime = dynamicArray[count].payRate * dynamicArray[count].hoursWorked;
}
}

double Total;

for (int index = 0; index < 4; index++)
{
Total = basePay + Overtime;
}

ofstream outFile; // Handle for the output file

string outputfileName; // complete file name include the path

outputfileName = getOutputFileName(); // prompt and obtain the full file
// name

outFile.open(outputfileName.c_str()); // try to open the file

if (!outFile.is_open()) // test for unsuccessful file opening
{
cerr << "Cannot open file: " << outputfileName << endl << endl;
exit (0);
}

for (int index = 0; index < 4; index++)
{
outFile << "Employee Number: " << dynamicArray[index].empNumber << endl << "Department: "
<< dynamicArray[index].department << endl << "Pay Rate: " << dynamicArray[index].payRate << endl
<< "Exempt: " << dynamicArray[index].exempt << endl << "Hours Worked: " << dynamicArray[index].hoursWorked << endl
<< "Base Pay: " << basePay << endl << "Overtime Pay: " << Overtime << endl << "Total Pay: " << Total << endl << endl;
}

inFile.close(); // close the input file
outFile.close(); // close the output file
}

//********************************************************************
//
// Function name: getInputFileName
//
// Purpose: to prompt for the fully qualified name of a file
//
// Input parameters: none
//
// Output parameters: none
//
// Return Value: a string containing the fully qualified name of a file
//
//********************************************************************

string getInputFileName()
{
string infName; // fully qualified name of the file

cout << "Please enter the fully qualified name of the " << endl
<< "input data file (i.e. including the path): ";

cin >> infName; // cannot handle blanks in a file name or path

cout << endl; // skip a line

return infName;
}

//********************************************************************
//
// Function name: getOutputFileName
//
// Purpose: to prompt for the fully qualified name of a file
//
// Input parameters: none
//
// Output parameters: none
//
// Return Value: a string containing the fully qualified name of a file
//
//********************************************************************

string getOutputFileName()
{
string outfName; // fully qualified name of the file

cout << "Please enter the fully qualified name of the " << endl
<< "output data file (i.e. including the path): ";

cin >> outfName; // cannot handle blanks in a file name or path

cout << endl; // skip a line

return outfName;
}
For all arrays, you need to tell the compiler how many values you want it to hold. I'm not sure why it's giving you that error, but I am sure that if you put a valid size in there, for example any positive number, it should go away.
Topic archived. No new replies allowed.