Hey guys, I need help with another one of those I/O File coding. I am super clueless and this is what I have so far:
/*Write a program that merges the numbers in two files and writes all the
numbers into a third file. Your program takes input from two different files and writes
its output to a third file. Each input file contains a list of numbers of type int in sorted
order from the smallest to the largest. After the program is run, the output file will
contain all the numbers in the two input files in one longer list in sorted order from
smallest to largest. Your program should define a function that is called with the two
input-file streams and the output-file stream as three arguments.*/
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int num1, num2;
ifstream inputFile;
ifstream inputFile2;
inputFile.open ("input1.txt");
inputFile2.open("input2.txt");
ofstream outputFile;
outputFile.open("output.txt");
inputFile >> num1;
inputFile2 >> num2;
while(inputFile.eof() && inputFile2.eof())
{
if (num1 < num2)
{
outputFile << num1;
inputFile >> num1;
}
else
{
outputFile << num2;
inputFile2 >> num2;
}
}
inputFile.close();
inputFile2.close();
outputFile.close();
return 0;
}
input1.txt
1 2 3 4 4 5 6 7 7 7 8 9 10 20
input2.txt
11 12 13 14 14 15 15 15 16 17 18 19 20
Please help, no arrays yet. I am only up to functions so nothing too fancy as I am a beginner.