vector of lists of elements

Sorry for my inglish but i have a problem and i dont know why i can iterate a list of lists of <subArbol>.

1
2
3
4
5
6
7
8
9
10
using namespace std;

struct subArbol{
	string paquete;
	string hijoDe;

vector<list<subArbol> >::iterator nivel;
for ( nivel = arbolPaquetes.begin() ; nivel < (arbolPaquetes).end(); nivel++){
	list<subArbol>::iterator iteraPaquete;
	for ( iteraPaquete = nivel.begin() ; iteraPaquete < *nivel.end(); iteraPaquete++)


Actualy i cant iterate the lists, and i dont know why.
If u cant understand, i can explain my code.
Last edited on
Please post your code in code tags, see <> button on right menu when posting.

First of all, using less than < is bad practice for iterators, and from what I remember, list::iterator does not support it.
So use != instead:
for ( nivel = arbolPaquetes.begin() ; nivel != (arbolPaquetes).end(); nivel++)

And then nivel, I think should be used as:
for ( iteraPaquete = (*nivel).begin() ; iteraPaquete != (*nivel).end(); iteraPaquete++)
OMFG, i love u.
So i cant iterate to the last element, i just have to compare, thanks a lot :)
Don't say you love me until after you test the code!

So i cant iterate to the last element, i just have to compare, thanks a lot :)

The last element IS NOT .end().
end() is the exact next position after the last element.

Edit:
http://cplusplus.com/reference/stl/list/end/
Last edited on
Topic archived. No new replies allowed.