cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Vectors?
Vectors?
Sep 6, 2014 at 1:32pm UTC
danielmccarthy
(126)
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
Sep 6, 2014 at 1:45pm UTC
Sep 6, 2014 at 3:06pm UTC
Peter87
(11234)
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.