#include#include using namespace std; int main() { list
myList = {1, 2, 3, 4, 5}; // Get iterator to beginning of list list ::iterator it = myList.begin(); // Iterate through list using iterator while (it != myList.end()) { cout << *it << " "; ++it; } return 0; }
#includeThis code creates a list of strings and gets an iterator to the beginning of the list using the `begin()` function. It then checks if the list is not empty and prints out the first element using the iterator. These examples use the C++ Standard Library package `list`.#include using namespace std; int main() { list
myList = {"apple", "banana", "orange"}; // Get iterator to beginning of list auto it = myList.begin(); // Check if list is empty if (it != myList.end()) { cout << "First element: " << *it << endl; } return 0; }