Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Getting last element from vector (http://www.go4expert.com/forums/getting-element-vector-t17503/)

beginuser 13May2009 16:07

Getting last element from vector
 
i had just started working in C++ and started modifying a code which make use of vectors.
please help me out with this.

link_Node *pNode,*tempsegnode;; // here link_node is a class
vector<link_Node*> *pList;

pNode = (*pList)[i];

i want to find that a pNode is last in pList and if so i have to take some corrective measure.
i tried using end() API but not able to make it working

in other words i need to know what is last element in vector list pList and compare with pNode and if they r same i need to do some processing.

can someone help how to find last element from pList and then compare pNode and last element.

xpi0t0s 13May2009 16:26

Re: Getting last element from vector
 
you need back(), not end(). end() returns an iterator that points to the next "free" slot.

http://www.cplusplus.com/reference/stl/vector/back/

(found by plugging "c++ vector" into Google, so not a complex query. TFM is always worth an R.)


All times are GMT +5.5. The time now is 14:50.