Similar Problems not available
The std::copy is a library function of algorithm header of C++ Standard Library which is used to copy the elements of a container. This function copies all the elements of a container for the given range to another container.
Syntax:
std::copy(Iterator startingAddress, Iterator endingAddress, Iterator targetStart);
Parameter: The std::copy() function accepts the following parameters that are given below:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
void print_array(int data[], int n)
{
for(int i = 0; i < n; ++i)
cout << data[i] << " ";
}
int main()
{
int Source[] = { 1, 2, 3, 4, 5};
int Target[5];
copy(Source, Source + 5, Target);
cout << "Source: ";
print_array(Source, 5);
cout << endl;
cout << "Target: ";
print_array(Target, 5);
return 0;
}
Source: 1 2 3 4 5
Target: 1 2 3 4 5