If std::vector <TMyClass> MyVector; --> How to remove MyVector[i] ?

Discussion in 'C++' started by Guest, Jul 26, 2004.

  1. Guest

    Guest Guest

    Say we have a vector defined as

    std::vector <TMyClass> MyVector;

    and we appended N number of element (N>1) to our vector (ie. MyVector.size()
    is N)

    How can we remove/delete an individual element MyVector (where 0<i<N) in
    such a way that after the remove/delete operation MyVector.size() will be
    N-1 ?
     
    Guest, Jul 26, 2004
    #1
    1. Advertising

  2. Re: If std::vector <TMyClass> MyVector; --> How to remove MyVector?

    zoom wrote:
    > Say we have a vector defined as
    >
    > std::vector <TMyClass> MyVector;
    >
    > and we appended N number of element (N>1) to our vector (ie. MyVector.size()
    > is N)
    >
    > How can we remove/delete an individual element MyVector (where 0<i<N) in
    > such a way that after the remove/delete operation MyVector.size() will be
    > N-1 ?


    Use vector::erase() member function. Make the iterator that points
    to the i-th element by applying + to the result of a call to 'begin()'.

    V
     
    Victor Bazarov, Jul 26, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anonymous
    Replies:
    20
    Views:
    4,358
    Pete Becker
    Mar 30, 2005
  2. Jason Heyes
    Replies:
    8
    Views:
    742
    Andrew Koenig
    Jan 15, 2006
  3. Replies:
    8
    Views:
    1,970
    Csaba
    Feb 18, 2006
  4. Replies:
    3
    Views:
    340
    terminator
    Mar 25, 2007
  5. Rune Allnor
    Replies:
    4
    Views:
    965
    Rune Allnor
    Dec 11, 2008
Loading...

Share This Page