How do you iterate backwards through an STL list?

前端 未结 5 1872
眼角桃花
眼角桃花 2020-12-08 09:25

I\'m writing some cross-platform code between Windows and Mac.

If list::end() \"returns an iterator that addresses the location succeeding the last element in a list

5条回答
  •  無奈伤痛
    2020-12-08 10:05

    Use reverse_iterator instead of iterator. Use rbegin() & rend() instead of begin() & end().

    Another possibility, if you like using the BOOST_FOREACH macro is to use the BOOST_REVERSE_FOREACH macro introduced in Boost 1.36.0.

提交回复
热议问题