#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
usingnamespace std;
int main()
{
int numTitles = 0;
vector<string>::iterator finder;
vector<string>::const_iterator iter;
vector<string> titles(numTitles);
cout << "\t\tWelcome!\n\n";
string choice;
while(choice != "quit")
{
cout << "\n\nWould you like to list your favorite games (type 'list')\n" << endl;
cout << "add more titles to your list (type 'add')\n" << endl;
cout << "or remove any titles from your list? (type 'remove')\n\n";
cin >> choice;
if (choice == "add")
{
++numTitles;
string addTitle;
cout << "\n\nEnter the name of the title you wish to add to the list: ";
cin >> addTitle;
titles.push_back(addTitle);
cout << "\nThe title " << addTitle << " was added to the list.\n";
}
if (choice == "list")
{
if (numTitles > 0)
{
cout << "\nYour favorite games are: \n\n";
for (iter = titles.begin(); iter != titles.end(); ++iter)
cout << *iter << endl;
}
else
cout << "\n\nYou have no titles listed.\n\n";
}
if (choice == "remove")
{
string removeTitle;
string remover;
cout << "\nWhich title would you like to remove?\n";
cin >> removeTitle;
for (finder = titles.begin(); *finder != removeTitle; finder++)
remover = *finder;
titles.erase(titles(remover));
--numTitles;
cout << "\nThe title " << removeTitle << " has been removed.\n";
}
}
return 0;
}
The part shown in bold is what I have a question about. I realize I'm not using the erase() function correctly, that is, because the book I'm learning from does not get into detail about it. What I'm trying to do is cycle through the list created by the user until the word specified (by the user) is equal to a word (added to the list by the user) in the list. Once the iterator is equal to the word specified, the program should delete the word from the vector. If anyone could help me with a correct way of doing this that would be awesome.
I apologize if this is sloppy, horribly incorrect, or too difficult to understand. I'm new to programming so any criticism, tips, etc. on anything else would be great. Thanks.