The program asks for the users favorite games, then to add, remove, or finish the list. I can't figure out how to remove a game within the vector. I've tried the erase() member function and the find() function. This is the main loop.
vector<string> favGames;
string game, action;
vector<string>::iterator it1;
vector<string>::const_iterator iter;
do
{
cout << "Here is your list of games:\n";
for (iter = favGames.begin(); iter != favGames.end(); ++iter)
cout << *iter << endl;
cout << "\nWhat would you like to do? (add, remove, finish)\n";
cin >> action;
if (action == "add") {
cout << "What game would you like to add?: "; // add a game
cin >> game;
favGames.push_back(game);
}
elseif (action == "remove"){
cout << "What game would you like to remove?\n"; // remove a game
cin >> game;
it1 = find(favGames.begin(), favGames.end(), game); //HERE'S MY PROBLEM
favGames.erase(*it1);
}
elseif (action != "add" || action != "remove" || action != "finish")
cout << "That is not an option.";
} while (action != "finish");
// Critique on anything else you notice is welcomed
// using std::find with vector and iterator:
std::vector<int> myvector {4,6,8,50,100};
std::vector<int>::iterator it;
it = find (myvector.begin(), myvector.end(), 30);
if (it != myvector.end()) // this is required.
std::cout << "Element found in myvector: " << *it << '\n';
else
std::cout << "Element not found in myints\n";