Quick STL iterator question

Status
Not open for further replies.

DaemonBlood

Ars Tribunus Militum
2,294
Alright ive been using SGI's stl site as a reference and have had limited success using vectors and whatnot from the stl. I've run into a problem though.

How do you use a returned iterator from say, a vector. Im not sure what headers to include or anything. If you havnt guessed I've used mostly Java in the past and am used to an iterator class where you can do something like.

while (iterator.value() !=end)
{ object = iterator.next();
}
(in rough pseudo code)

can anyone give me a quick example of how to use an iterator from a vector in c++ and stl?
 
Hmmmmm...not to nitpick but... I like this better:
Code:
transform(myIntVector.begin(), myIntVector.end(), bind2nd(plus<int>(), 1));
:p

Edit: To add to the original answer, all STL containers must define nested types for their iterators. These are usually iterator, const_iterator, reverse_iterator, and const_reverse_iterator. You should always use those types to store iterators.

Edit2: Oh and check out the SGI pages on the iterator concepts. Basic stuff, but it's nice to know if you want to understand the ideas behind the STL.

[This message was edited by euzeka on March 13, 2002 at 19:19.]
 
Status
Not open for further replies.