I have a program that has a set of items that you can add and delete from including a const iterator, pair and of course set.
one of my switch cases for the main program is to locate an item and the other is to delete, but both use the same .find(item) function and compare the iterator to .end() to determine if it was located
#include<iostream>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include <set>
#include <iterator>
#include "Item.h"
usingnamespace std;
//Function prototypes
...
//end function prototypes
int main()
{
constint MAX = 10;
set<Item> itemList;
set<Item>::const_iterator loc;
pair<set<Item>::const_iterator,bool> pairSet;
int menuOption;
Item item;
programIntro();
bool menuDisplayed=false;
char* model;
//do while loop for menu option
switch(menuOption)
{
case 1: //enter information for an item
...
case 2://delete a item
if(itemList.empty())
{
cout << "List is Empty" << endl;
}else{
Item toDelete = getModelKey("Please Enter an item model to delete: ");
loc = itemList.find(toDelete);
if(loc!=itemList.end()){
itemList.erase(*loc);
cout<<"The "<<toDelete.getModel()<<
" was successfully deleted"<<endl;
}else{
cout<< "There are no "<<toDelete.getModel()<<"'s in the list"<<endl;
}
}
break;
case 3: //locate the item
if(itemList.empty())
{
cout << "The List is Empty" << endl;
}else{
Item toFind = getModelKey("Please Enter an item model to find: ");
loc = itemList.find(toFind);
if(loc==itemList.end()){
cout<< "There are no "<<toFind.getModel()<<"'s in the list"<<endl;
}else{
cout<<toFind<<endl;
}
}
break;
and in the item class I have these < than and == operators
Header file:
The cases can never find the item
I tried changing set<Item>::const_iterator loc; to iterator<set<Item>::const_iterator,bool> loc; but then it says there are errors on the operands to the left of loc