好的,所以我首先开始学习C#,现在我正在学习C++,所以我对它很陌生。
在C#中,当我想要访问列表中的列表时,我只需要使用嵌套for-each循环。如何访问C++列表中的列表?
现在,因为在C++中我不知道如何使用for-each循环,我尝试使用for循环访问嵌套列表。
这里是我的代码:
int main
{
list<list<char *> > moves;
list<char *> pointers;
list<list<char> > undoValues;
list<char> undoValue;
for(list<list<char *> >::iterator outer=moves.begin();outer!=moves.end();outer++)
{
for(list<char *>::iterator inner=outer.begin();inner!=outer.end();inner++)
{
}
}
}
我得到2个错误:
error 'struct std::_List_iterator<std::list<char*>,std::allocator<char *> > >' has no member named begin
error 'struct std::_List_iterator<std::list<char*>,std::allocator<char *> > >' has no member named end
如何访问嵌套列表?
+1列出了两种可能性。 – egrunin 2012-07-19 14:39:09