Write a program that opens two text files (input1.txt and input2.txt) for
input and one for output (output.txt). The program should merge the two input files in the output files.
While doing the merge, it will read one line from input1.txt and one line from input2.txt
and write those in the output file one after other. Then it will read the next line from input1.txt and
next line from input2.txt and write them one after other in the output file.
This is my code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ofstream myproject;
myproject.open("input1.txt");
myproject<<"This is the first line in input1.txt.\n";
myproject<<"This is the second line in input1.txt.\n";
myproject<<"This is the third line in input1.txt.\n";
myproject<<"This is the fourth line in input1.txt.\n";
myproject.close();
ofstream mypro;
mypro.open("input2.txt");
mypro<<"This is the first line in input2.txt.\n";
mypro<<"This is the second line in input2.txt.\n";
mypro<<"This is the third line in input3.txt.\n";
mypro.close();
I need help on:
1. how to get the second line in the input1.txt file and so on.
2. After the writing in output.txt, count the number of lines in output.txt.
3. write the number of times term ‘line’ appears in output.txt file.
first ... always use different objects to open different files simultaneously.
you can use jump statement to get the merged output.
put a statement count=count+2 ; after that jump statement.