// Test - Display inventory
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Invent {
public:
void Invent::displayInventory();
void Invent::addItem(string item);
void Invent::removeItem(string item);
private:
vector<string> Inventory;
vector<string>::const_iterator iter;
};
int main() {
Invent invent;
unsigned int userChoice;
bool quit = false;
cout << "\nWelcome to your item inventory" << endl;
while (quit == false) {
cout << "\n1. Display inventory" << endl;
cout << "2. Add item" << endl;
cout << "3. Remove item" << endl;
cout << "4. Quit\n" << endl;
cout << "Option: ";
cin >> userChoice;
string item = "";
switch (userChoice) {
case 1:
invent.displayInventory();
break;
case 2:
cout << "\nPlease type the item name: ";
cin.get();
getline(cin, item);
invent.addItem(item);
break;
case 3:
cout << "\nPlease type the item name to remove: ";
cin.get();
getline(cin, item);
invent.removeItem(item);
break;
case 4:
quit = true;
break;
default:
cout << "\nYou entered an incorrect value!\n";
break;
}
}
return 0;
}
void Invent::displayInventory() {
if (Inventory.empty()) {
cout << "\nSorry but your inventory is currently empty.\n";
}
else {
cout << "\nDisplaying all the current items in your inventory.\n" << endl;
for (iter = Inventory.begin(); iter != Inventory.end(); ++iter) {
cout << "- " << *iter << endl;
}
}
}
void Invent::addItem(string item) {
Inventory.push_back(item);
cout << "\nThe item \"" << item << "\" was successfully added to your inventory." << endl;
}
void Invent::removeItem(string item) {
iter = find(Inventory.begin(), Inventory.end(), item);
if (iter != Inventory.end()) {
Inventory.erase(item); // ERROR something about overloaded op
}
}
ICAvLyBUZXN0IC0gRGlzcGxheSBpbnZlbnRvcnkKCiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPHZlY3Rvcj4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpjbGFzcyBJbnZlbnQgewpwdWJsaWM6Cgl2b2lkIEludmVudDo6ZGlzcGxheUludmVudG9yeSgpOwoJdm9pZCBJbnZlbnQ6OmFkZEl0ZW0oc3RyaW5nIGl0ZW0pOwoJdm9pZCBJbnZlbnQ6O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ZyBhYm91dCBvdmVybG9hZGVkIG9wCgl9Cn0K
prog.cpp:11:7: error: extra qualification ‘Invent::’ on member ‘displayInventory’ [-fpermissive]
void Invent::displayInventory();
^
prog.cpp:12:7: error: extra qualification ‘Invent::’ on member ‘addItem’ [-fpermissive]
void Invent::addItem(string item);
^
prog.cpp:13:7: error: extra qualification ‘Invent::’ on member ‘removeItem’ [-fpermissive]
void Invent::removeItem(string item);
^
prog.cpp: In member function ‘void Invent::removeItem(std::string)’:
prog.cpp:83:54: error: no matching function for call to ‘find(std::vector<std::basic_string<char> >::iterator, std::vector<std::basic_string<char> >::iterator, std::string&)’
iter = find(Inventory.begin(), Inventory.end(), item);
^
prog.cpp:83:54: note: candidate is:
In file included from /usr/include/c++/4.8/bits/locale_facets.h:48:0,
from /usr/include/c++/4.8/bits/basic_ios.h:37,
from /usr/include/c++/4.8/ios:44,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from prog.cpp:3:
/usr/include/c++/4.8/bits/streambuf_iterator.h:369:5: note: template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(std::istreambuf_iterator<_CharT>, std::istreambuf_iterator<_CharT>, const _CharT2&)
find(istreambuf_iterator<_CharT> __first,
^
/usr/include/c++/4.8/bits/streambuf_iterator.h:369:5: note: template argument deduction/substitution failed:
prog.cpp:83:54: note: ‘__gnu_cxx::__normal_iterator<std::basic_string<char>*, std::vector<std::basic_string<char> > >’ is not derived from ‘std::istreambuf_iterator<_CharT>’
iter = find(Inventory.begin(), Inventory.end(), item);
^
prog.cpp:85:23: error: no matching function for call to ‘std::vector<std::basic_string<char> >::erase(std::string&)’
Inventory.erase(item); // ERROR something about overloaded op
^
prog.cpp:85:23: note: candidates are:
In file included from /usr/include/c++/4.8/vector:69:0,
from prog.cpp:5:
/usr/include/c++/4.8/bits/vector.tcc:134:5: note: std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(std::vector<_Tp, _Alloc>::iterator) [with _Tp = std::basic_string<char>; _Alloc = std::allocator<std::basic_string<char> >; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<std::basic_string<char>*, std::vector<std::basic_string<char> > >; typename std::_Vector_base<_Tp, _Alloc>::pointer = std::basic_string<char>*]
vector<_Tp, _Alloc>::
^
/usr/include/c++/4.8/bits/vector.tcc:134:5: note: no known conversion for argument 1 from ‘std::string {aka std::basic_string<char>}’ to ‘std::vector<std::basic_string<char> >::iterator {aka __gnu_cxx::__normal_iterator<std::basic_string<char>*, std::vector<std::basic_string<char> > >}’
/usr/include/c++/4.8/bits/vector.tcc:146:5: note: std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(std::vector<_Tp, _Alloc>::iterator, std::vector<_Tp, _Alloc>::iterator) [with _Tp = std::basic_string<char>; _Alloc = std::allocator<std::basic_string<char> >; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<std::basic_string<char>*, std::vector<std::basic_string<char> > >; typename std::_Vector_base<_Tp, _Alloc>::pointer = std::basic_string<char>*]
vector<_Tp, _Alloc>::
^
/usr/include/c++/4.8/bits/vector.tcc:146:5: note: candidate expects 2 arguments, 1 provided