class Print
{
public:
void PrintAll() {}
private:
std::list<int> mylist;
};
I see this example question from a C++ language book.
And I want to print the internal mylist elements.
How can it be done if mylist needs to be reversed, using C++ STL library and using to output the result.
Thanks you very much!
std::list<>::reverse()?That said, if you only need to print the
listin reverse, you can simply print it usinglist‘s reverse iterators (obtained bystd::list<>::rbegin()andstd::list<>::rend()) rather than by usinglist‘s normal iterators. E.g.: