Iterator help

Hello, I have a question regarding the first 'else if' statement. I'm trying to remove a string from 'library' but I get an error when it comes to the iterator. I'm barely learning about them and vectors. It gives me the error "no match for 'operator='. I originally had that part set to
cin>>game;
library.empty(game);
but I got an error saying 'no matcching function for call to'
Can someone help me please.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  #include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
	char choice;
	string gameTitle;
	
	while (choice !='4')
	{
		cout<<"----What would you like to do?-----\n";
		cout<<"(1)Add a new game to your library?\n";
		cout<<"(2)Remove a game from your library?\n";
		cout<<"(3)View your game library";
		cout<<"(4)Quit the program?\n";
		cin>>choice;
	
		vector<string> library;
		if(choice=='1')
		{
			//add game
			cout<<"Please enter the game title. ";
			cin>>gameTitle;
			library.push_back(gameTitle);
		}
		else if(choice=='2')
		{
			//remove game
			cout<<"Please select which game to remove from your library.";
			for (int i=0;i<library.size();i++)
			{
				cout<<"("<<i<<") "<<library[i];
			}
			int game;
			cin>>game;
			
			vector<int>::iterator myIterator;
			myIterator = library[game];
			*myIterator=library.empty();
			
		}
		else if(choice=='3')
		{
			//view library
			for (int i=0;i<library.size();i++)
			{
				cout<<library[i];
			}
		}
		else
		{
			cout<<"Please enter a valid option.";
		}
	
	}
	
	cout<<"Thank you for using this program.";
	
	return 0;
}
*myIterator=library.empty();


This doesn't do what you think.

library.empty() does not modify the vector. It just tells you information about it.

empty() will return true if the vector is empty (has no elements), or it will return false if it has at least 1 element.

If you want to remove a specific element from the vector, you want erase():

1
2
3
4
5
6
7
8
vector<int>::iterator myIterator = library.begin(); // start with the first iterator (begin)
myIterator += game;  // add 'game' to it to advance it to the 'game'th element in the vector.
    // At this point, 'myIterator' now points to the element you want to remove.
library.erase( myIterator );  // erase the element that our iterator points to


//  ... or ...  more simply:
library.erase( library.begin() + game );
alright I tried it and fixed it. Thank you for the solution and thank you for how quickly you responded!
Topic archived. No new replies allowed.