Erasing from vectors

say I have:

vector<string> list;

which contains the words:

the
and
fry
bug
pie

and I want to remove bug, but I didn't know its exact position in the vector (I don't know the order of this list before running the program), how would I do that?
search and find position. And delete.
and I would do that.. how?
Take first in vector and compare, if not it look to second and so on. Until the end off vector.
You should use find to locate the string and delete that.
1
2
3
4
5
6
7
8
typedef std::vector<std::string> stringlist_t;
//...
stringlist_t::iterator p = std::find(list.begin(), list.end(), "bug");
if (p != list.end())
{
    // we found the position of bug
    list.erase(p);
}
It can be done in one line

list.erase( std::find( v.begin(), v.end(). "bug" ) );
thank you
Topic archived. No new replies allowed.