Write a program that opens two text files for input and one for output. The prog
ID: 3632448 • Letter: W
Question
Write a program that opens two text files for input and one for output. The program should concatenate the corresponding lines of the input files, use a space as a separator, and write the results to the output file. If one file is shorter than the other, the remaining lines in the longer file should also be copied to the output file.For example, suppose the first input file has these contents:
eggs kites donuts
balloons hammers
stones
And suppose the second input file has these contents:
zero lassitude
finance drama
The resulting file would have these contents:
eggs kites donuts zero lassitude
balloons hammers finance drama
stones
Please post screenshot when posting answer.
Explanation / Answer
std::ifstream fin1("org1.txt") std::ifstream fin2("org2.txt") std::ofstream fout("new.txt") while (true) { std::string str1,str2; if (fin1) std::getline(fin1,str1); if (fin2) std::getline(fin2,str2); if (!fin1 && !fin2) break; foutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.