From: Ramon F Herrera on

I need to have the option of outputting the data contained in a list
in a forward or in reverse fashion.

The forward iteration is easy enough:

for (list<string>::iterator itr = mylist.begin(); itr != mylist.end();
itr++)

I naively tried to reverse it like this:

for (list<string>::iterator itr = mylist.end(); itr != mylist.begin();
itr--)

But then I realized that the issue is not that simple, as you are not
supposed to find anything usable at the list.end().

Should I try to reverse:

- The iterator?
- The list itself?

TIA,

-Ramon

From: Helge Kruse on
Did you try

for (list<string>::reverse_iterator itr = mylist.rbegin(); itr !=
mylist.rend(); itr++) ?


Helge


"Ramon F Herrera" <ramon(a)conexus.net> wrote in message
news:6a123b5f-20e9-4e70-8af7-770a43db4109(a)a21g2000yqc.googlegroups.com...
>
> I need to have the option of outputting the data contained in a list
> in a forward or in reverse fashion.
>
> The forward iteration is easy enough:
>
> for (list<string>::iterator itr = mylist.begin(); itr != mylist.end();
> itr++)
>
> I naively tried to reverse it like this:
>
> for (list<string>::iterator itr = mylist.end(); itr != mylist.begin();
> itr--)
>
> But then I realized that the issue is not that simple, as you are not
> supposed to find anything usable at the list.end().
>
> Should I try to reverse:
>
> - The iterator?
> - The list itself?
>
> TIA,
>
> -Ramon
>


From: Ramon F Herrera on
On Oct 13, 9:56 am, "Helge Kruse" <Helge.Kruse-nos...(a)gmx.net> wrote:
> Did you try
>
> for (list<string>::reverse_iterator itr = mylist.rbegin(); itr !=
> mylist.rend(); itr++) ?
>


Ah! That is the solution - I have seen those r-members around...

Thanks!

-Ramon