i need a little bit help with my code. The first part of the Code, was easy to create. Read from two textfiles -> Output in a new Textfile. My next step is, to compare the both outputs line by line.
If the number is the same, the numbers stays.
If the number is different to the number of textfile2,
the number with be replaced.
Example:
Textfile1:
2221112221
1122221112
2222221111
1111111111
Textfile2:
2222221111
2211222212
1111111111
2221112222
Result that should happen on Textfile3:
(like im overlapping textfile2 on textfile1)
2222221111
2211222212
1111111111
2221112222
So i already researched for str.compare, but im not able to output the result as above stated. I don't know if this works with it..
if((line2.compare(0, line2.length(), line1)) == 0)
string line1, line2; ifstream read1, read2;
read1.open("test.txt", ios::in);
read2.open("test2.txt", ios::in);
ofstream outFile("outputfile.txt", ios::out | ios::app);
if(!read1 || !read2){
cerr << "One file is missing" << endl;
exit(1);
}
else {
while(getline(read1, line1))
{
outFile << line1;
}
while(getline(read2, line2))
{
outFile << line2 << endl;
}
Thanks a lot guys!
Aucun commentaire:
Enregistrer un commentaire