I have a separate issue now... Before I reduce the main file of the duplicates and do not calls, I need to group the file by id key code. How would I remove the duplicate part of this program to just search for duplicates of the same string and put them in a file. My code so far for this is:
Code:
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <functional>
#include <set>
#include <string>
#include <algorithm>
using namespace std;
int i=0;
struct Search : unary_function<string, bool>
{
string value;
Search(const string& val) : value (val) {}
bool operator()(const string& a)
{
return a.compare(17,10,value,0,4) == 0;
}
};
struct compare: binary_function<string, string, bool> {
bool operator()(const string& a, const string& b)
{
return a.compare(18,10,b,18,10)>0;
}
};
void Annotate ( const string& inSource2)
/* Searches given file with user entered keycodes and appends
to the user given file with the extension of .all*/
{
string line;
string filename="box";
string keyCode;
int knum=2;
set<string,compare> strSet;
set<string,compare>::iterator it;
ifstream in(inSource2.c_str());
cout<<"Using "<<inSource2<<" as master file."<<endl;
//cout<< "Enter your new file name: ";
//getline(cin,filename); hard coded for testing
filename+=".all";
cout << "Your File Name is " << filename <<endl;
//cout<<"Enter number of key codes: ";
//cin>>knum; Hard coded for testing
cout<<"Thinking..."<<endl;
ofstream out(filename.c_str());
while (getline(in,line))
strSet.insert(line);
while (knum!=0)
{
cout<<"Enter a Key Code: ";
getline(cin,keyCode);
cin.ignore(1,'\n');
it = find_if(strSet.begin(),strSet.end(),Search(keyCode));
if (it != strSet.end())
{
}
knum--;
}
copy(strSet.begin(),strSet.end(),(out,
}
int main (void)
{
int Groupnum;
cout<<"How many files? ";
cin>> (Groupnum);
cout<<"Your number is "<<Groupnum<<endl<<endl;
while (Groupnum !=0)//allows you to enter multiple files
{
Annotate("tested.all");
--Groupnum;
}
return(0);
}
My last program I didn't have a problem with the get line function after I fixed the string bug and using the fix in the stdafx.h file. But in this one it does some funky things. It will at times automatically press enter without allowing the user to enter the filename(when not hard coded) Program should allow you to pick multiple files to make and in each of those files to add multiple keycodes to such file. pulling from the tested.all file. I changed the offset but I need to get rid of the duplicate killer? Any suggestions...