Is using the arrays a mandatory part of this assignment? Or can you use std::vector instead?
Please explain what you think the following line is doing?
I would recommend opening the file stream in main(), checking that it opened properly, and then passing that open stream to your getData() function. Or another option would be to change your function to return a value to indicate success of failure, using exit() in a C++ program should be avoided whenever possible since it doesn't properly call C++ destructors.
Next look at this snippet:
1 2 3 4 5 6 7 8 9 10
|
ifstream fin;
fin.open("empdata2.txt");
int i;
fin >> i;
if (fin.fail()) {
cout << " Your file was unable to open.\n\n";
exit(1);
}
|
1.) You really should get into the habit of using class constructors to open your files instead of calling open.
2.) You should really consider using meaningful variable names, what is the purpose of that variable named i?
3.) You try to read from the file before you insure the file actually opened, does that make sense?
4.) Again avoid the C function exit(). In this case you have other options, return an error code to the calling function or throw an exception for example.
5.) How does the calling function know how many records your file contained?
6.) Have you considered a vector/array of a structure or class to hold the record information?
Please use code tags when posting code!