#include#include int main() { std::list
myList; myList.push_back(1); myList.push_back(2); myList.push_back(3); for (auto i : myList) { std::cout << i << " "; } return 0; }
#includeThis code creates an empty forward list, then adds four elements to the list using push_front() and push_back(). Finally, it prints the contents of the list to the console. This code also uses the C++ Standard Library.#include int main() { std::forward_list myList; myList.push_front(3); myList.push_front(2); myList.push_front(1); myList.push_back(4); for (auto i : myList) { std::cout << i << " "; } return 0; }