I need to compare the a string from codes.dat to a string in sales.dat and if they are equal do nothing for now and i will implement it later, if they don't equal I want to go through the whole sales.dat set to find if they equal. If I find one that doesn't I want to remove that from the set.
I am having issues with the compare at the moment and don't really have a lot of experience with sets so I was wondering if ya'll could help me out.
The error occurs at line 90, and there is most likely an error at line 92 as well
Also in a realated problem when I put the the sets in a function ie...
And I include everything I get a boat load of errors/warnings and I was wondering if anyone could help me out with that have the function set up like..
You can't compare iterators into different containers. It's like thinking the first child one one family is same as the first child in a different family.
You probably what to compare the item the iterator indicates, in which you have to dereference them:
Umm now I run into issues when my sales.dat has more than 1 sales code in it and it have to control C to end it. I get this when there more than one sale codes in that data file:
I have modified my code a little bit but not much. I was also wondering if there is a way to get the last integer of the codes through the iterators, I've been working with that for a while but to no avail. The commented out section at the bottom is where I am trying to work with that.
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <set>
usingnamespace std;
//--------------------------------------------------
//------------Main Function-------------------------
//--------------------------------------------------
int main() {
long codesMax = 15; //const for the amount of codes that there are to be
int saleCodesNum = 0; //the number of codes that produce a 10 cent donation
int numCodes = 0; //the amount of codes that there actually are
set<string> codes1; //the set for codes1
set<string> saleCodes1; //the set for the codes that produce a 10 cent donation
set<string>::iterator it; //iterator to go through the sets
set<string>::iterator it2; //iterator to go through the sets
set<string>::iterator it3; //iterator to go through the sets
string codes; //an array of the codes that can later be inserted into the set
string saleCodes; //an array of the codes that produce 10 cents to the foundation
ifstream codesFile; //the file that codes come from.
ifstream salesFile; //the file that sales codes come from.
int breakFromSearch = 0;
//------------------------------------
//--the sales of each type of yogurt--
//------------------------------------
int vanillaSales = 0;
int strawberrySales = 0;
int blueberrySales = 0;
int raspberrySales = 0;
int keylimeSales = 0;
int mixedberrySales = 0;
int rainbowSales = 0;
int bostoncreampieSales = 0;
int redvelvetcakeSales = 0;
int mangoSales = 0;
//--------------------------------------------------------------------
//------function calls and implimentation-----------------------------
//--------------------------------------------------------------------
codesFile.open("codes.dat");
salesFile.open("sales.dat");
//-------------------------------------------------------------------------
//-----------------------read from file------------------------------------
//-------------------------------------------------------------------------
if(codesFile){
while(codesFile >> codes){
numCodes++;
codes1.insert(codes);
}
}
else
cout << "The file did not open correctly." <<endl;
if(salesFile){
while(salesFile >> saleCodes){
saleCodesNum++;
saleCodes1.insert(saleCodes);
}
}else
cout << "The file did not open correctly." << endl;
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
codesFile.close();
salesFile.close();
cout << "codes inserted " << endl;
for (it=codes1.begin(); it!=codes1.end(); it++){
cout << " " << *it;
}
cout << endl;
cout << "sale codes " << endl;
for (it=saleCodes1.begin(); it!=saleCodes1.end(); it++){
cout << " " << *it;
}
cout << endl;
for(it=codes1.begin(); it!=codes1.end(); it++){
for(it2=saleCodes1.begin(); it2!=saleCodes1.end(); it2++)
{
if(*it==*it2){
cout << "it == it2...it worked!!" <<endl;
}elseif(breakFromSearch==saleCodesNum){
cout << "printing *it: " << *it << endl;
cout << "printing set after removed.\n";
codes1.erase(it);
for (it3=codes1.begin(); it3!=codes1.end(); it3++)
cout << " " << *it3;
cout << endl;
}else{
breakFromSearch++;
}
}
}
/* for(it=codes1.begin; it!=codes1.end(); it++)
{
if(*it.substr(4,5)==0){
vanillaSales++;
}else if(*it[5]==1){
strawberrySales++;
}else if(*it[5]==2){
blueberrySales++;
}else if(*it[5]==3){
raspberrySales++;
}else if(*it[5]==4){
keylimeSales++;
cout << "Key Lime Sales: " << keylimeSales << endl;
}
}*/
return 0;
}