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 bkrike 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
Jul 5, 2001
222
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.

Part and Inventory Search

Sponsor

Back
Top