#include #include #include #include //insert_iterator, front_insert_iterator, back_insert_iterator using namespace std; int main() { const int a[] = {30, 70, 80}; const size_t n = sizeof a / sizeof a[0]; list li(a, a + n); list::iterator it = li.begin(); insert_iterator > in(li, ++it); //Refer to the 70. *in = 40; //Insert 40 immediately in front of the 70. //At this point, in still refers to the 70. *in = 50; //Insert 50 immediately in front of the 70. //At this point, in still refers to the 70. ++in; //++ does nothing to an inserter: in still refers to the 70. *in = 60; //Insert 60 immediately in front of the 70. front_insert_iterator > fi(li); *fi = 20; //Insert 20 at the front of the list. *fi = 10; //Insert 10 at the front of the list. back_insert_iterator > bi(li); *bi = 90; //Insert 90 at the end of the list. *bi = 100; //Insert 100 at the end of the list. for (it = li.begin(); it != li.end(); ++it) { cout << *it << " "; } cout << "\n"; return EXIT_SUCCESS; }