For Programmers: Free Programming Magazines  


Home > Archive > VC STL > February 2005 > Re: Newbie STL iterator question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Newbie STL iterator question
Jerry Coffin

2005-02-14, 9:11 pm

In article <n97iv0956ohsdg3if8537q6dfdth20l4h7@4ax.com>, me@you.twang
says...

> I want to be able to use an iterator as a pointer to a structure
> stored in the vector.


No problem -- but you should be aware that there's rarely a reason to
do this. A vector acts like an array (but safer) so most of the time,
it's perfectly reasonable to just index into it like normal:

vector<CarDef> m_vCards;

for (int i=0; i<m_vCards.size(); ++i)
TRACE("%i \n", m_vCards[i]);

Don't feel obliged to make your life more difficult than necessary
just to make your code seem more "STL-like". :-)

--
Later,
Jerry.

The universe is a figment of its own imagination.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com