I am not sure how to get the numbers to print in ascending order when I input them into numbers1.txt and numbers2.txt. I am having numbers repeat themselves among other things!
I suggest, read file1 and file two inside a vector - std::vector<int>.
you will have text in the input files, so convert the string to numbers using atoi/atol and then push inside the vectors.
sort the vector using std::sort. Output them to the output file. You will again have to convert them to string. You can use a stringstream or sprintf function to convert number to a string.
Edit: I know this is totally different from what you are doing but that would be easy for you.
atoi/sprintf are totally unnecessary; the stream overloads are just fine.
While sorting vector or using multiset would produce expected output, is that the goal? Or the beef in the logic?
You seem to start well. Then you reach the point, where one or both streams are at end and the latest number from each has not been output. If they are equal, both should be written. If not, one stream still may have values and the challenge is to insert the value of the exhausted stream at correct position.
How about a function that reads from one stream and inserts "pivot value" when suitable. Then call that function with appropriate input.