does this function pop out the top value in a vector? how do i pop out the top value and store it in another variable? it doesn't work when i do this:
x = stringvector.pop_back();
does this function pop out the top value in a vector? how do i pop out the top value and store it in another variable? it doesn't work when i do this:
x = stringvector.pop_back();
Vectors don't have a pop() function. Why not just use the [] operator? If you want the first element it'd be vectorname[0], if you want the last element it'd be vectorname[vectorname.size()];
Check the syntax of the pop_back function, its possible you have to pass a variable reference in rather than returning one.Originally posted by Vector Man
does this function pop out the top value in a vector? how do i pop out the top value and store it in another variable? it doesn't work when i do this:
x = stringvector.pop_back();
Couldn't think of anything interesting, cool or funny - sorry.
It supports and erase() method:
vector::size_type size;
size = svec.size();
svec.erase(size);
But you should also probably be using iterators to identify the type.
Last edited by Troll_King; 09-03-2002 at 04:23 AM.
Some function definitions:
vector's pop_back()'s return type is void. back() returns a reference to the last element, so just use that before you pop_back()Code:void pop_back(); reference back(); const_reference back() const; //The member function returns a reference to the last element of the controlled sequence, which must be non-empty.
here's a list of all the functions in vector:
just look at 'vector' in MSVC or check out this link at dinkumware:Code:vector allocator_type ˇ assign ˇ at ˇ back ˇ begin ˇ capacity ˇ clear ˇ const_iterator ˇ const_reference ˇ const_reverse_iterator ˇ difference_type ˇ empty ˇ end ˇ erase ˇ front ˇ get_allocator ˇ insert ˇ iterator ˇ max_size ˇ operator[] ˇ pop_back ˇ push_back ˇ rbegin ˇ reference ˇ rend ˇ reserve ˇ resize ˇ reverse_iterator ˇ size ˇ size_type ˇ swap ˇ value_type ˇ vector
http://dinkumware.com/manuals/reader...&h=vector.html
Originally posted by Eibro
Vectors don't have a pop() function. Why not just use the [] operator? If you want the first element it'd be vectorname[0], if you want the last element it'd be vectorname[vectorname.size()];Code:vectorname[vectorname.size()-1]; //Or my program is buggier than I think
Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling
d'oh... i was thinking of a queueOriginally posted by Eibro
Vectors don't have a pop() function. Why not just use the [] operator? If you want the first element it'd be vectorname[0], if you want the last element it'd be vectorname[vectorname.size()];
I do that all the time. I know better, yet I still do it. That's it, i'm outta here.Originally posted by Sang-drax
Code:vectorname[vectorname.size()-1]; //Or my program is buggier than I think