My assignment is to read two separate text files(file1.txt and file2.txt) and merge them into a 3rd file(output.txt), then sort the new output file and display. File1 is simply odd numbers from 1 to 9, and file2 is the even numbers from 0 to 8.
I successfully created a program to merge the two files into the third file, but I'm stuck on how to sort the file before displaying it. Is there a function that'll do that?
in_stream1.getline(input1, SIZE); on line 32 does not extract integers, the same thing goes for line 42.
You need to extract the numbers from both files and store them in a single std::vector<int>. After that you have to sort the container using std::sort(). After that you have to traverse the std::vector<int> printing each element into the third file.
Vector isn't something I'm familiar with. This is an Intro to C++ course, so that may be above my pay grade. I'll do some research on it. Thanks for the input.
As a programmer you are regularly going to have to research topics that you are not familiar with, but that are required by the needs of the project you are working on.
Will vector automatically convert a char into an int?
No.
Instead of extracting the data from the file as characters you should extract the data as integers. For example, let's say you have a file called "a.txt" with the following data:
I'm trying to follow the logic. Forgive me, I haven't programmed since I had a TRS-80 Color as a kid.
Basically, Instead of extracting with a getline function and writing that into file3, I extract the data from file1 and file2 into a temporary vector of ints, sort that, then write the contents of the vector into file3?