copy array c 2b 2b

Solutions on MaxInterview for copy array c 2b 2b by the best coders in the world

showing results for - "copy array c 2b 2b"
Laurel
23 Apr 2018
1#include <algorithm>
2#include <iterator>
3
4const int arr_size = 10;
5some_type src[arr_size];
6// ...
7some_type dest[arr_size];
8std::copy(std::begin(src), std::end(src), std::begin(dest));
9
Jacob
13 May 2016
1#include <algorithm> //Only needed for Option 1
2#include <iostream>
3
4using namespace std;
5
6int main() {
7  	//Option 1
8    const int len{3};
9    int arr1[len] = {1,2,3};
10    int arr2[len]; //Will be the copy of arr1
11    copy(begin(arr1), end(arr1), begin(arr2));
12  
13  	//Use the following, if you are not using namespace std;
14    //std::copy(std::begin(arr), std::end(arr), std::begin(copy));
15  
16    //Option 2
17    int arr3[len]; //Will be the copy of arr1
18    for(int i = 0; i<len; ++i) {
19      arr3[i] = arr1[3];
20    }
21    
22    return 0; //exitcode
23};