Vectors?

Hi,
I am trying to pop the element on a vector off and return its value at the same time

vector.push_back();

Unfortunatly that code only removes that element from the vector it does not return it

Is the only way to get the element and destory it is to do this?

1
2
vector.back();
vector.pop_back();


Thanks
Last edited on
Yeah you will have to copy (or move) the last element in the vector before you call pop_back(). The reason it doesn't return the removed element is because it would have to create a copy and that would be wasteful if you don't need the copy.
Topic archived. No new replies allowed.