Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vector STL

Status
Not open for further replies.

jimberger

Programmer
Joined
Jul 5, 2001
Messages
222
Location
GB
Hello all,

How do i erase an element from a STL vector?

I want to be able to delete a given subscript element,

for example i have a vector<int> numbers(10);

i then have
for(int i=0;i<11;i++)
{
numbers = i+4;
}

then i want to delete whatever is in subscript element 5
that is numbers[5],

numbers.erase(5) will delete numbers[0]

any ideas?

thanks


 
numbers.erase(numbers.begin() + 5) will erase element 5. erase needs a pointer to the element to erase, not the index. Use numbers.begin() + i to erase the ith element.
 
Status
Not open for further replies.

Similar threads

  • Locked
  • Question Question
Replies
7
Views
437
  • Locked
  • Question Question
Replies
8
Views
443
Replies
4
Views
448

Part and Inventory Search

Sponsor

Back
Top