|
From: Ioannis V. <iv...@at...> - 2003-04-08 05:36:49
|
> -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of David McKen > Sent: Monday, April 07, 2003 9:50 PM > To: Dev-C Mailing List > Subject: [Dev-C++] STL Vector > > > This may sound really stupid but here goes. > > I have a vector of objects (STL vector, just an arbritary > class). I have just pushed an object onto the end of this > vector. I want the index (the number I put in [] to access > the object) of the object I pushed onto the back. How would > I do so? (vector.size()?, or .end()) The straight way to do it is myarray[myarray.size()-1] Another way to do with [] is: myarray[myarray.end()-myarray.begin()-1] Or you can access it with iterator: E.g.: vector<int>::iterator p; //... p=myarray.end()-1; *p=7; Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL 1: http://run.to/noicys * Alternative URL 2: http://www.noicys.cjb.net Anti-racism movement: http://www.positive-youthfoundation.org Iraq Peace Pledge: http://www.peacepledge.org |