I have to compare two files, and I was thinking that in order to do that I have to input them into arrays. So, When I try doing that by reading the files line by line it does not work (using getline(myfile,x)). So I think I will change it to myfile.get(x). So my problem is how from that point can I input the file into an array, and how do I compare the lines between the files.
Thank you
#include <conio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
string filename;
cout << "Enter filename: ";
cin >> filename;
cout << endl;
ifstream myFile;
myFile.open(filename.c_str());
if (myFile.fail())
{
cout << "Failed to open the file: ";
cout << filename << endl;
}
else
{
string filename2;
cout << "Enter filename: ";
cin >> filename2;
cout << endl;
ifstream myFile2;
myFile2.open(filename2.c_str());
if (myFile2.fail())
{
cout << "Failed to open the file: ";
cout << filename2 << endl;
}
else
{
string line;
string line1;
int i = 0;
int count = 0;
int count2 =0;
do
{
getline(myFile,line);
cout << setw(3) << ++i << " * ";
cout << line <<endl;
count++;
} while (!myFile.eof());
cout << endl;
cout << "The second text is: "<< endl;
cout << endl;
i=0;
do
{
getline(myFile2,line1);
cout << setw(3) << ++i << " ** ";
cout << line1 <<endl;
count2++;
} while (!myFile2.eof());
cout << endl;
cout <<"The number of lines the first text has is: " << count;
cout << " and the second text has: " << count2 << " lines ";
const int size = 1000;
string list[size];
string list1[size];
list[1000]=line+line;
list1[1000]=line1+line1;
cout << line;
cout << line1;
}
myFile.close();
myFile2.close();
cout << endl;
}
cout << "\nHit any key to quit" << endl;
_getch();
return 0;
}

New Topic/Question
Reply




MultiQuote




|