1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
char fillComma = ',';
char result,
zeroChecker;
int peekNum;
ifstream firstFile,
secondFile;
string amount1,
amount2,
accountNumber1,
accountNumber2,
compareSecond;
ofstream finalFile;
//prompting the user for the file names
/*
cout << "Enter the name of the first file you want to use as input: ";
cin >> firstName;
cout << endl;
cout << "Enter the name of the file taken from EAS: ";
cin >> secondName;
cout << endl;
cout << "Enter the name of the file you want the final product stored to: ";
cin >> finalName;
cout << endl;
*/
// opening the files
firstFile.open("InputFile1.txt");
secondFile.open("InputFile2.txt");
finalFile.open("OutputFile.txt");
while (!firstFile.eof())
{
{
//grabbing the name of the first account name to be compared to the second account name
getline(firstFile, accountNumber1, fillComma);
getline(firstFile, amount1);
// removing the zeroes from the account name in the second file
// cycling through all the accounts in the second file until an account with a matching name and amount are found
while (!secondFile.eof())
{
getline(secondFile, accountNumber2, fillComma);
accountNumber2.erase(0, accountNumber2.find_first_not_of('0'));
getline(secondFile, amount2, fillComma);
secondFile.get(result);
//if an account with a mathing name and amount are found storing the information in the final file
if (accountNumber1 == accountNumber2 && amount1 == amount2)
{
finalFile << accountNumber1 << fillComma << amount1 << fillComma << result << endl;
cout << accountNumber1 << fillComma << amount1 << fillComma << result << endl;
}
// if no matching accounts are found continuing the cycle
getline(secondFile, accountNumber2, fillComma);
}
}
}
firstFile.close();
secondFile.close();
finalFile.close();
return 0;
}
|