AW: [Insight-users] STL vector iterator
salah
salah at gris.uni-tuebingen.de
Wed Aug 11 11:12:15 EDT 2004
Thanks Frederic,
one more question please.
I am calling the erase function to erase the elements of the vector
between these two iterators as follows:
std::cout << "Contour length BEFORE cutting = " << contour.size() << std::endl;
contour.erase(startIter, endIter);
std::cout << "Contour length AFTER cutting = " << contour.size() << std::endl;
The strange thing is that the printed length of the counter after erasing
elements is greater than before!
Could you guess what is going on?
Many thanks,
Zein
> -----Ursprüngliche Nachricht-----
> Von: FREDERICPCX [mailto:FREDERICPCX at terra.es]
> Gesendet: Wednesday, August 11, 2004 4:57 PM
> An: salah
> Cc: insight-users at itk.org
> Betreff: Re: [Insight-users] STL vector iterator
>
>
>
> Hello Zein,
>
> if your vector is called v, maybe you can simply use something like
> the following:
>
> if (distance(v.begin(), iter1) < distance(v.begin(), iter2) { ...
>
> Beware that calling some methods on the STL containers can invalidate
> their related iterators. More in Chapter 23 of the 1997 C++ Public
> Review Document: http://anubis.dkuug.dk/jtc1/sc22/open/n2356/
>
> Hope this helps,
>
> Frederic
>
> ----- Mensaje Original -----
> De: "salah" <salah at gris.uni-tuebingen.de>
> Fecha: Miercoles, Agosto 11, 2004 4:38 pm
> Asunto: [Insight-users] STL vector iterator
>
> > Hello,
> >
> > I am using two iterators to point to two different
> positions on an STL
> > vector. I want to decide which iterator is advancing more that the
> > other.is it meaningful to just compare the two iterator? i.e.
> > something like this
> >
> > typedef std::vector< ...... > VectorType;
> > VectorType::iterator iter1, iter2;
> > ....
> > ....
> > if (iter1 < iter2) {
> > ....
> > ....
> > }
> >
> > or something else is needed. This comparison does not seem
> > to work by me.
> >
> > Thanks,
> > Zein
> > _______________________________________________
> > Insight-users mailing list
> > Insight-users at itk.org
> > http://www.itk.org/mailman/listinfo/insight-users
> >
>
>
>
More information about the Insight-users
mailing list