Deleting duplicate vectors

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void MovieUser::AddMovie()
{
	string userTitle;


	cout << "\nTitle: ";
	cin.ignore();
	getline(cin, userTitle);
	MovieRating *p = new MovieRating(userTitle);
	moviesSeen.push_back(p);
	for (int i=0; i < moviesSeen.size();i++)
	{
	    if (userTitle == moviesSeen[i]->title)
	    {
	        moviesSeen.pop_back();
	    }
	}
}


The code above of for a function that stores a movie title. i dont want it to store duplicate strings and the code i have right now will just delete every input. Thanks for the help
std::set would seem appropriate here.
If you want to keep the vector, push after checking for duplicates. Now you push a new item, find it and then pop it. Move line 10 down after 17 and change line 15 with a return.
so why dont you first look for the title before you add it to your vector? :)
Topic archived. No new replies allowed.