lists of lists

J

Jon Slaughter

I'm using C++ and I'm trying to create a list of a list and it won't let me
create an iterator for it. if I do a list of an int, everything is fine.

my syntax is

list<list<string> > some_list;

and my iterator would be someting like

list<list>::Iterator blah;

or maybe

list<list<string> >::Iterator blah;

??

neither work, ofcourse.

basicaly I'm trying to parse a text file, each line is token that contains
tokens and I have a function that takes a string and returns the list of the
tokens. so I have my the parent list to contain lists to the tokens.

so I need to push onto the list

so in some sense Parent_List is "tokenized" version of the ith line in
the text file.

I thought about using a pointer to list<strings>, but then I'd have to
allocate the memory and I'd rather let C++ do all the dirty work. but even
then I had a problem allocating memory for my list<string> **ptr_list = new
list<string>[30]?

any idea's?
 
D

Dave O'Hearn

Jon said:
and my iterator would be someting like

list<list>::Iterator blah;

or maybe

list<list<string> >::Iterator blah;

??

neither work, ofcourse.

Could the problem just be the capital on "Iterator"? I tried this, and
it works fine,

list<list<string> > stuff;
list<list<string> >::iterator i = stuff.begin();
 
K

Karl Heinz Buchegger

Jon said:
I'm using C++ and I'm trying to create a list of a list and it won't let me
create an iterator for it. if I do a list of an int, everything is fine.

my syntax is

list<list<string> > some_list;

and my iterator would be someting like

list<list>::Iterator blah;

or maybe

list<list<string> >::Iterator blah;

??

neither work, ofcourse.

which error message do you get ?

Note: I prefer using typedef to split things into
readable junks:

typedef list<string> StringList;
typedef list<StringList> Dictionary;

Dictionary MyDic;
Dictionary::iterator blah;
 
J

Jon Slaughter

Dave O'Hearn said:
Could the problem just be the capital on "Iterator"? I tried this, and
it works fine,

list<list<string> > stuff;
list<list<string> >::iterator i = stuff.begin();

yes, you were right... turns out I don't really need it though ;) I just use
list like a stack for now and its working out nice.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top