title: how to find and erase item from vector C++
body: <p>I have a vector:</p>
  
  <pre><code>std::vector&lt;User*&gt; myFriends_;
  </code></pre>
  
  <p>Then I have code to see if the element <code>theFriend</code> exists in the vector.</p>
  
  <pre><code>if (std::find(myFriends_.begin(), myFriends_.end(), theFriend)!=myFriends_.end())
              return FAILURE;
  </code></pre>
  
  <p>I would like to do some thing like </p>
  
  <pre><code>User* toErease;
  toErease=std::find(myFriends_.begin(), myFriends_.end(), theFriend);
  if (toErease!=myFriends_.end())
                  return FAILURE;
  myFriends_.erase(toErease); /// remove this element if its precent
  </code></pre>
  
  <p>Will it work?</p>
  
  <p><code>find</code> returns the location of the element</p>
  
  <p>And <code>erase</code> needs the index as far as I know.</p>