template <class InputIterator, class OutputIterator> OutputIterator copy( InputIterator qFirst, InputIterator qLast, OutputIterator 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 copy(qV.begin(), qV.end(), qCopy.begin() + 1); // 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; }
© 20072024 XoaX.net LLC. All rights reserved.