Hello! I am working on a lab for my class, and I am having trouble with File I/O. I need to open two files, "datafile1.txt" and "datafile2.txt", and pass them to a function that will get the first line as an int variable. An example text file (datafile1.txt) is:
4
Dana Smith F
River Jones M
Jordan Pollic F
Liska Fanta M
So I pass my stream to my function, and I don't know where to go from here in terms of differentiating between the two functions. This is what I have right now and I know it's not right, but I'm not sure how to fix it.
int main() {
// Declare variables
dataRecord record;
// Open files for input
std::ifstream inFile1;
std::ifstream inFile2;
if(!inFile1.is_open()) {
std::cout << "Sorry, could not open file." << std::endl;
exit (0);
}
if(!inFile2.is_open()) {
std::cout << "Sorry, could not open file." << std::endl;
exit (0);
}
inFile1 = inFile1.open("datafile1.txt");
inFile2 = inFile2.open("datafile2.txt");
// Make function calls to get size to use in new statement to create dynamic array
int numRecordsInFile1 = readHeader(inFile1);
int numRecordsInFile2 = readHeader(inFile2);
// Get dynamic memory
int totalRecord = numRecordsInFile1 + numRecordsInFile2;
record * ArrayPtr = new dataRecord[totalRecord];