Thread: vector::erase!

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    132

    vector::erase!

    I need some help erasing a specific item from my vector array.
    I am trying to use vector::erase method, but I can't find the iterator to use. All I know it the index to that item.

    ( texture[nIndex] for example, nIndex is UINT)
    How can I erase, say, item 5 from the array using vector::erase? Also, does it sort it after it so there is no "blank"?
    Thanks!
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    101
    If you know the index then you can find an iterator to it by doing vec.begin() + index. So the erase would look like:
    Code:
    vec.erase(vec.begin() + index);
    - lmov

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    132
    Oh right, thanks!!
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Another solution is remove().

    Kuphryn

Popular pages Recent additions subscribe to a feed