interleave: Write a utility program interleave that reads two file names from st
ID: 3658390 • Letter: I
Question
interleave: Write a utility program interleave that reads two file names from standard input and then writes their content out to to a new file, interleaving the lines of the two files (the first line from the first file, then the first line from the second file, then the second line from the first file, then the second from the second, then the third line from the first file followed by the third line from the second file and so on). The name of the new file should be the name of the first file followed by a dot followed by the name of the second file. So if the two input files were "data1" and "data2" then the resulting file would be "data1.data2". And if the two input files were "junk" and "bunk" then the resulting file's name would be "junk.bunk". The two files might have different numbers of lines. If that turns out to be the case, then the program will just copy the extra lines of the longer file to the end of the output file. EXAMPLE: If the files were "f1" which consisted of two lines: First line of f1 Second line of f1 and "f2" which consisted of 5 lines: L1 L2 L3 L4 L5 then the resuting file, "f1.f2" would consist of: First line of f1 L1 Second line of f1 L2 L3 L4 L5 I have no idea how to do this, please help.Explanation / Answer
//fixed to treat unequal lenght files #include #include #include using namespace std; void createtestfile(){//for testing purpose string datA="A1 A2 A3 A4"; string datB="B1 B2 B3 B4 B5"; ofstream make("testA.dat"); makeRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.