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 91 92 93 94 95 96 97 98 99 100 101 102
|
#include <iostream>
#include <algorithm>
#include <vector>
#include <fstream>
#include <string>
using namespace std;
int main()
{
vector<string> rawList;
vector<string> excelList;
vector<string> missing;
ifstream infile;
ifstream excel;
infile.open("test.txt");
excel.open("test2.txt");
if (infile.fail() || excel.fail())
{
cout << "Could not open file." << "\n";
return 1;
}
string data;
string excel2;
//This gets each line from the txt file, lowers them all to lowercase
//Then it finds where the = sign is and gets the position of the next four
//characters which is the unique ID.
while (getline(infile, data))
{
transform(data.begin(), data.end(), data.begin(),
[](unsigned char c) { return tolower(c);});
size_t pos;
if ((pos = data.find('=', 0)) != string::npos)
{
rawList.push_back(data.substr(pos + 1, 4));
}
}
//This takes the first four characters of each line and pushes it into the vector
//since the unique I.D in this file is at the beginning of each line.
while (getline(excel, excel2))
{
transform(excel2.begin(), excel2.end(), excel2.begin(),
[](unsigned char c) { return tolower(c);});
size_t pos = excel2.find(" ");
if(pos != std::string::npos)
{
excelList.push_back(excel2.substr(0,4));
}
}
sort(rawList.begin(), rawList.end());
auto last = unique(rawList.begin(), rawList.end());
rawList.erase(last, rawList.end());
// for (const auto& i : rawList)
// cout << i << " " << endl;
sort(excelList.begin(), excelList.end());
auto opp = unique(excelList.begin(), excelList.end());
excelList.erase(opp, excelList.end());
// for (const auto& i : excelList)
//cout << i << " " << endl;
// cout << "\n";
//This is to compare the two txt files and see which values are missing from the second file.
/* string found;
for(int i = 0; i < sizeOfrawList; i++)
{
string found = " ";
for(int k=0; k < sizeOfexcelList; k++ )
{
if( rawList.at(i) == excelList.at(k))
{
break;
}
if(rawList.at(i) != excelList.at(k))
{
found = rawList.at(i);
}
}
//cout<< rawList.at(i) << endl;
missing.push_back(found);
}
*/
std::set_difference(rawList.begin(), rawList.end(), excelList.begin(), excelList.end(),
std::inserter(missing, missing.begin()));
for (const auto& i : missing){
cout << i << " " << endl;
cout << "\n";
}
}
| |