hello im trying to compare 2 text file and find if the string in the first file exist or not.
first text file:
11111 22222 33333 44444 55555 77777
second text file:
11111 22222 44444 AAAAA BBBBB 55555 66666 CCCCC
The output should be:
11111 Match found
22222 Match found
33333 No Match
44444 Match found
55555 Match found
77777 No Match
what i got is:
11111 Match found
22222 Match found
33333 No Match
44444 No Match
55555 No Match
77777 No Match
This is my code:
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main(){
    ifstream File1;
    ifstream File2;
    ofstream File3;
    string line,line2;
File1.open("A.txt");
File2.open("B.txt");
File3.open("OutputA.txt");
if(File1.fail()){ cerr<<"Error opening file !!"<<endl;exit(1);}
if(File2.fail()){ cerr<<"Error opening file !!"<<endl;exit(1);}
while(!File1.eof()){ //read file until you reach the end
        getline(File1,line);
    getline(File2,line2);
     if(line==line2){
    File3<<line<<"   Match"<<endl;
     }
     else{
         File3<<line<<"   Not Match"<<endl;
    }
        }
File1.close();
File2.close();
File3.close();
return 0;
}
 
    