deleting vector

void Person::SearchDelete(int numDelAccount)
{
for (unsigned int i=0; i < accounts.size(); i++)
{
if(accounts[i]->getaccountNumber()==numDelAccount)
{
accounts.erase(i);
}
}
}


I have written this to delete a specified account number "numDelAccount" by searching the array of accounts, but when I run it, it says "account deleted" after apparently using the SearchDelete function, but when I check the accounts list upon returning to the menu, it has not deleted the account, can someone tell me what I am missing?
It shouldn't let you just pass an integer into the erase function. Try this instead.
accounts.erase(accounts.begin() + i);

Otherwise we will need to see more of your code.
This seems to of worked, it has a little issue if it is trying to delete the last object in the array, but other than that it is manageable

Much appreciate thank you :)
Topic archived. No new replies allowed.