in C++ I need to open 4 text files and print the contents of each line which sho
ID: 3817012 • Letter: I
Question
in C++
I need to open 4 text files and print the contents of each line which should be a string into a coulumn side by side with the other outputs.
string of file 1 line 4
This is a table to compare the outputs of three different programs, but the outputs are written as strings so there is context, not just integers.
Thanks
String of file 1 line 1 String of file 2 Line 1 String of File 3 LIne 1 String of File 4 Line1 String of file 1 line 2 string of file 2 line 2 string of file 3 line 2 string of file 4 line2 string of file 1 line 3 string of file 2 line 3 string of file 3 line 3 string of file 4 line 3string of file 1 line 4
string of file 2 line 4 string of file 3 line 4 string of file 4 line 4 string of file 1 line 5 string of file 2 line 5 string of file 3 line 5 string of file 4 line 5Explanation / Answer
#include<iostream>
#include<fstream.h>
using namespace std;
int main()
{
ifstream in1,in2,in3,in4;
in1.open("file1.txt");
in2.open("file2.txt");
in3.open("file3.txt");
in4.open("file4.txt");
string h1,h2,h3,h4;
while(!in1.eof() && !in2.eof() && !in3.eof() && !in4.eof() )
{
in1>>h1;
in2>>h2;
in3>>h3;
in4>>h4;
cout<<h1<<" "<<h2<<" "<<h3<<" "<<h4<<" ";
}
in1.close();
in2.close();
in3.close();
in4.close();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.