#include
#include
#include
using namespace std;
int main()
{
vector vectorObject, vectorObject2;
vector::iterator itr;
int i;
for(i = 0; i <5; i++)
vectorObject.push_back(i);
cout << "Original contents of vectorObject: ";
itr = vectorObject.begin();
while(itr != vectorObject.end())
cout << *itr++ << " ";
cout << endl;
back_insert_iterator > bck_i_itr(vectorObject); // create a back_insert_iterator to vectorObject
*bck_i_itr++ = 100; // insert rather than overwrite at end
*bck_i_itr = 200;
cout << "vectorObject after insertion: ";
itr = vectorObject.begin();
while(itr != vectorObject.end())
cout << *itr++ << " ";
cout << endl;
cout << "Size of vectorObject2 before copy: " << vectorObject2.size() << endl;
copy(vectorObject.begin(), vectorObject.end(), back_inserter(vectorObject2)); // copy vectorObject to vectorObject2 using back inserter
cout << "Size of vectorObject2 after copy: " << vectorObject2.size() << endl;
cout << "Contents of vectorObject2 after insertion: ";
itr = vectorObject2.begin();
while(itr != vectorObject2.end())
cout << *itr++ << " ";
return 0;
}