Assuming you're looking for an element containing the value 2 , not the value in index 2 .
#include<vector> #include<algorithm> int main(){ std::vector<int> a={1,2,3}; a.erase(std::find(a.begin(),a.end(),2)); }
(I used C ++ 0x to avoid some pattern, but the actual use of std::find and vector::erase does not require C ++ 0x)
Ken bloom
source share