Answers for "copy array c++"

C++
2

copy array c++

#include <algorithm>
#include <iterator>

const int arr_size = 10;
some_type src[arr_size];
// ...
some_type dest[arr_size];
std::copy(std::begin(src), std::end(src), std::begin(dest));
Posted by: Guest on July-03-2021
0

array copx c++

#include <algorithm> //Only needed for Option 1
#include <iostream>

using namespace std;

int main() {
  	//Option 1
    const int len{3};
    int arr1[len] = {1,2,3};
    int arr2[len]; //Will be the copy of arr1
    copy(begin(arr1), end(arr1), begin(arr2));
  
  	//Use the following, if you are not using namespace std;
    //std::copy(std::begin(arr), std::end(arr), std::begin(copy));
  
    //Option 2
    int arr3[len]; //Will be the copy of arr1
    for(int i = 0; i<len; ++i) {
      arr3[i] = arr1[3];
    }
    
    return 0; //exitcode
};
Posted by: Guest on October-23-2020

Browse Popular Code Answers by Language