Program :
Code:
#include <algorithm>
#include <iostream>
#include <vector>
int main ()
{
typedef std::vector<short, std::allocator<short> > vector;
const vector::valuetype e1[] = { 1, 2, 3, 4 };
const vector::valuetype e2[] = { 5, 6, 7, 8 };
vector w1(e1 + 0, e1 + 4),
w2(e2 + 0, e2 + 4),
w3(e2 + 0, e2 + 4);
vector w4;
std::copy(w1.begin(), w1.end(), w2.begin());
std::copybackward(w1.begin(), w1.end(), w3.end());
std::copy(w1.begin(), w1.end(), std::backinserter(w4));
std::ostreamiterator<vector::valuetype, char,
std::chartraits<char> > out(std::cout, " ");
std::copy(w1.begin(), w1.end(), out);
std::cout << std::endl;
std::copy(w2.begin(), w2.end(), out);
std::cout << std::endl;
std::copy(w3.begin(), w3.end(), out);
std::cout << std::endl;
std::copy(w4.begin(), w4.end(), out);
std::cout << std::endl;
return 0;
}
Output :
Code:
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
Bookmarks