void DeleteMovie(vector<Movie> &M1){
cout << "Option selected: delete a movie from the database" << endl;
string T1;
int TT=0;
if(M1.size()<1){
cout << ">Error: There are no movies to delete.<" << endl;
}
else{
cin.ignore(100,'\n');
cout << "Enter the title of the movie you want deleted: ";
getline(cin,T1);
for(int i=0;i<M1.size()+1;i++){
if(M1[i].Get_Title()==T1){
M1.erase(M1.begin()+i);
cout << "Movie deleted." << endl;
TT++;
}
}
if(TT==0)
cout << "No results found, no deletions made.";
}
}
That's the function I'm using. I have a vector that has a movie title in it. The user enters the movie title and if there is a match, it deletes that movie from the vector.
If the user enters a movie that matches and it gets deleted, and then the user searches for a movie that has no match, the program runs fine. But if the user types in a movie that has no match first, the program crashes. Any ideas why?