#include#include using namespace std; int main() { StringList myList; myList.push_back("apple"); myList.push_back("banana"); myList.push_back("cherry"); myList.print(); // prints: "apple banana cherry" return 0; }
#includeThis code example creates a list object called myList and adds three strings to it using the push_back function. It then uses a for loop to iterate through the list and print each element. This code uses the standard library list package.#include using namespace std; int main() { list
myList; myList.push_back("dog"); myList.push_back("cat"); myList.push_back("bird"); for(auto it = myList.begin(); it != myList.end(); ++it) { cout << *it << " "; } return 0; }