Insert one vector into another using an insert iterator
#include <iostream>
#include <iterator>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> vectorObject, vectorObject2;
vector<string>::iterator itr;
vectorObject.push_back("T");
vectorObject.push_back("S");
vectorObject.push_back("A");
vectorObject.push_back("P");
vectorObject2.push_back("A");
vectorObject2.push_back("I");
vectorObject2.push_back("S");
cout << "Original size of vectorObject: " << vectorObject.size() << endl;
cout << "Original contents of vectorObject:\n";
itr = vectorObject.begin();
while(itr != vectorObject.end())
cout << *itr++ << " ";
cout << endl;
copy(vectorObject2.begin(), vectorObject2.end(), inserter(vectorObject, vectorObject.begin() + 2));
cout << "Size of vectorObject after insertion: ";
cout << vectorObject.size() << endl;
cout << "Contents of vectorObject after insertion:";
itr = vectorObject.begin();
while(itr != vectorObject.end())
cout << *itr++ << " ";
return 0;
}
Related examples in the same category