This program allows for a user to add an items storage location and search for an item by name to find it later. I am getting a weird error when I try and run my code. Everything was working fine until I added in a search
function for the vector. Any ideas on what is going wrong since I don't see a line item issue?
The red section of GDB error report says this:
/tmp/ccngGZSU.o: In function `bool __gnu_cxx::__ops::_Iter_equals_val<item const>::operator()<__gnu_cxx::__normal_iterator<item*, std::vector<item, std::allocator<item> > > >(__gnu_cxx::__normal_iterator<item*, std::vector<item, std::allocator<item> > >)':
main.cpp:(.text._ZN9__gnu_cxx5__ops16_Iter_equals_valIK4itemEclINS_17__normal_iteratorIPS2_St6vectorIS2_SaIS2_EEEEEEbT_[_ZN9__gnu_cxx5__ops16_Iter_equals_valIK4itemEclINS_17__normal_iteratorIPS2_St6vectorIS2_SaIS2_EEEEEEbT_]+0x2b): undefined reference to `operator==(item const&, item const&)'
collect2: error: ld returned 1 exit status
The code is only 150 lines long, so 199:17 doesn't exist as far as I know.
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct item {
string name;
string color;
string size;
string location;
};
void additem()
{
int num;
cout << "How any items do you wish to add? " << endl;
cin >> num;
vector<item> items(num);
item hold;
for (vector<item>::size_type i = 0; i < items.size(); i++) {
cout << "What is the item name? " << endl;
cin >> hold.name;
cout << "What is the item color? " << endl;
cin >> hold.color;
cout << "What is the item size? " << endl;
cin >> hold.size;
cout << "What is the item location? " << endl;
cin >> hold.location;
items[i] = hold;
}
}
void search()
{
item s;
typedef vector<item> itemsearch;
typedef itemsearch::iterator itemiterator;
itemsearch items;
cout << "Enter the item name to search for. " << endl;
cin >> s.name;
cout << "Enter the item color to search for. " << endl;
cin >> s.color;
cout << "Enter the item size to search for. " << endl;
cin >> s.size;
itemiterator i;
i = find(items.begin(), items.end(), s);
if (i != items.end()) {
cout << "Item Found!" << endl;
cout << "The location is . . ." << endl;
cout << s.location << endl;
} else {
cout << "Item Not Found" << endl;
}
}
void menu()
{
int menu;
while (menu != 3) {
cout << "Please select an option from the menu to begin." << endl;
cout << "1. Add Item/s " << endl;
cout << "2. Search for Item " << endl;
cout << "3. Exit Program " << endl;
cin >> menu;
if (menu == 1)
{
cout << "You selected to add an item." << endl;
additem();
}
if (menu == 2)
{
cout << "You selected to search for an item." << endl;
search();
}
if (menu == 3)
{
cout << "Exiting Prgram." << endl;
cout << ". . . . ." << endl;
exit;
}
}
}
int main()
{
cout << "Welcome to Brandon's Box" << endl;
cout << "This program will allow you to add details about an item and where "
"it is stored."
<< endl;
menu();
}