Nuz25
Junior Member
- Aug 20, 2010
- 129
- 100
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream readFile1;
ifstream readFile2;
ofstream writeFile;
string temp, temp2;
bool duplicate=false;
readFile1.open("list1.txt");
readFile2.open("list2.txt");
writeFile.open("formated_list.txt");
if(readFile1.fail()||readFile2.fail())
cout<<endl<<"There was a problem opening your file"<<endl;
else
{
while(!(readFile1.eof()))
{
getline(readFile1,temp);
while(!readFile2.eof()&&!duplicate)
{
getline(readFile2,temp2);
if(temp==temp2)
{
duplicate=true;
}
}
if(!duplicate)
writeFile<<temp<<endl;
duplicate=false;
}
}
readFile1.close();
readFile2.close();
writeFile.close();
system("pause");
return 0;
}
This program is supposed to read list1 and list2 and rewrite list1 in formated list without the element that were included in list2 and list1.
I run with no errors but it's not removing the duplicates... (I'm a novice programmer and I'm not even sure you can read 2 files at a time..)
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream readFile1;
ifstream readFile2;
ofstream writeFile;
string temp, temp2;
bool duplicate=false;
readFile1.open("list1.txt");
readFile2.open("list2.txt");
writeFile.open("formated_list.txt");
if(readFile1.fail()||readFile2.fail())
cout<<endl<<"There was a problem opening your file"<<endl;
else
{
while(!(readFile1.eof()))
{
getline(readFile1,temp);
while(!readFile2.eof()&&!duplicate)
{
getline(readFile2,temp2);
if(temp==temp2)
{
duplicate=true;
}
}
if(!duplicate)
writeFile<<temp<<endl;
duplicate=false;
}
}
readFile1.close();
readFile2.close();
writeFile.close();
system("pause");
return 0;
}
This program is supposed to read list1 and list2 and rewrite list1 in formated list without the element that were included in list2 and list1.
I run with no errors but it's not removing the duplicates... (I'm a novice programmer and I'm not even sure you can read 2 files at a time..)