Standard C++ Library Class Reference

deque<int> d2(4, 1);
//
// Insert d2 at front of d.
//
copy(d2.begin(), d2.end(), front_inserter(d));
//
// Output the new deque.
//
cout << endl << endl;
cout << "Use a front_inserter: " << endl << " ";
copy(d.begin(), d.end(), ostream_iterator<int>(cout," "));
//
// Insert d2 at back of d.
//
copy(d2.begin(), d2.end(), back_inserter(d));
//
// Output the new deque.
//
cout << endl << endl;
cout << "Use a back_inserter: " << endl << " ";
copy(d.begin(), d.end(), ostream_iterator<int>(cout," "));
cout << endl;
return 0;
}
Output :
Start with a deque:
3 4 7 8
Use an insert_iterator:
3 4 5 6 7 8
Use a front_inserter:
1 1 1 1 3 4 5 6 7 8
Use a back_inserter:
1 1 1 1 3 4 5 6 7 8 1 1 1 1
Warning
If your compiler does not support default template parameters then you need to always supply
the Allocator template argument. For instance you'll have to write:
vector<int,allocator>
instead of:
vector<int>