#include#include int main() { std::list
mylist = {1, 2, 3, 4, 5}; auto it = mylist.end(); --it; // move iterator to last element std::cout << *it; // prints 5 return 0; }
#includeIn this example, we use the `insert()` function iterator to append new elements to the end of a list. We use `end()` to obtain an iterator pointing to the position after the last element in the list, which is where new elements will be inserted. We can insert a single element or multiple elements using a brace-enclosed list. The List end function is part of the C++ standard library, included in the#include int main() { std::list
mylist = {10, 20, 30}; mylist.insert(mylist.end(), 40); // add 40 to the end of the list mylist.insert(mylist.end(), {50, 60}); // add multiple elements to the end of the list for (auto element : mylist) { std::cout << element << " "; } // prints "10 20 30 40 50 60 " return 0; }