template <class BidirIterator1, class BidirIterator2> OutputIterator copy_backward( BidirIterator1 qFirst, BidirIterator1 qLast, BidirIterator2 qDest );
#include <algorithm>
#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
using namespace std;
// Create a vector instance
vector<int> qV;
qV.push_back(3);
qV.push_back(5);
// Create another vector that we will copy into
vector<int> qCopy;
qCopy.push_back(100);
qCopy.push_back(200);
qCopy.push_back(300);
qCopy.push_back(400);
qCopy.push_back(500);
vector<int>::iterator qIter;
// Output the vector before the copy
cout << "Before the copy:" << endl;
for (qIter = qCopy.begin(); qIter != qCopy.end(); ++qIter) {
cout << *qIter << " ";
}
cout << endl;
// Copy the first vector into the second, backward from dest.
copy_backward(qV.begin(), qV.end(), qCopy.begin() + 4);
// Output the vector after the copy
cout << "After the copy:" << endl;
for (qIter = qCopy.begin(); qIter != qCopy.end(); ++qIter) {
cout << *qIter << " ";
}
cout << endl;
// Keep the window open
cin.get();
return 0;
}
© 20072025 XoaX.net LLC. All rights reserved.