#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
vector<char> vectorObject(10);
vector<char> vectorObject2(10);
int i;
for(i = 0; i < 10; i++)
vectorObject[ i ] = 'A' + i;
for(i = 0; i < 10; i++)
vectorObject2[ i ] = 'z';
copy(vectorObject.begin(), vectorObject.end(), vectorObject2.begin()); // copy all of vectorObject into vectorObject2
cout << "Contents of vectorObject2 after copy:\n";
for(i = 0; i < 10; i++)
cout << vectorObject2[ i ] << " ";
cout << endl;
for(i = 0; i <10; i++) // re-initialize vectorObject2
vectorObject2[ i ] = 'z';
copy(vectorObject.begin() + 2, vectorObject.end() - 2, vectorObject2.begin()); // now copy just part of vectorObject into vectorObject2
cout << "Contents of vectorObject2 after subsequence copy:\n";
for(i = 0; i <10; i++)
cout << vectorObject2[ i ] << " ";
cout << endl;
for(i = 0; i <10; i++) // re-initialize vectorObject2
vectorObject2[ i ] = 'z';
// now copy part of vectorObject into middle of vectorObject2
copy(vectorObject.begin() + 2, vectorObject.end() - 2, vectorObject2.begin() + 3);
cout << "Contents of vectorObject2 after copy into middle:\n";
for(i = 0; i <10; i++)
cout << vectorObject2[ i ] << " ";
cout << endl;
return 0;
}
|