I'm trying to take two given text files from input of a directory path, take their integers, and output those integers into a "merged" text file. I'm new to C++ from Java, so this has been rather tricky thus far figuring out. This code builds and runs, but I'm not actually getting an output file. Any help?
Edit:
I have the merged file working, but I can't seem to get the data1 and data2 to sort into ascending order as they're implemented into the output file "merge.txt".
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
void textMerge(){
ifstream inFile1;
ifstream inFile2;
string inputFileName1;
string inputFileName2;
ofstream outputFile("merge.txt");
cout << "1. Please enter the directory path of the first text list: " << endl; // Open first file based on given directory path
cin >> inputFileName1;
inFile1.open(inputFileName1);
cout << "2. Please enter the directory path of the second text list: " << endl; // Repeat open file for second directory path
cin >> inputFileName2;
inFile2.open(inputFileName2);
if (inFile1.is_open() && inFile2.is_open()){
int data1;
int data2;
while(!inFile1.eof() && !inFile2.eof()){ // while both files haven't reached end-of-file yet
inFile1 >> data1; // get next number for first file
inFile2 >> data2;
// get next number for second file
outputFile << data1 << data2; // output each integer from files 1 and 2 to outputFile(merge.txt)
}
inFile1.close();
inFile2.close();
outputFile.close();
}
else{
cerr << "The file(s) failed to open properly.";
exit(0);
}
}
int main(){
textMerge();
}