#include#include using namespace std; int main() { // create a list of integers list
mylist = {10, 20, 30}; // insert element at the front mylist.insert(mylist.begin(), 5); // print the list for (auto it = mylist.begin(); it != mylist.end(); ++it) cout << *it << " "; return 0; }
#include#include using namespace std; int main() { // create a list of strings list
mylist = {"apple", "banana", "orange"}; // insert element at position 2 auto it = mylist.begin(); advance(it, 2); mylist.insert(it, "pear"); // print the list for (auto& x: mylist) cout << x << " "; return 0; }
#includeOutput: `a b b c d` Package library: STL#include using namespace std; int main() { // create a list of characters list
mylist = {'a', 'c', 'd'}; // insert elements at position 1 auto it = mylist.begin(); advance(it, 1); mylist.insert(it, 2, 'b'); // print the list for (auto& x: mylist) cout << x << " "; return 0; }