0

(C++) Copying Arrays

If I make an array, what's the easiest way to make an exact copy of that array?

29th Oct 2017, 7:56 AM
ReimarPB
ReimarPB - avatar
5 Respuestas
+ 5
I would also do @0xDEADBEEF solution but with a slit change : Remove #include <iterator> std::copy(arr,arr + 3,arr2); //copy arr in arr2
29th Oct 2017, 9:35 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 3
#include <algorithm> #include <iterator> int main() { int arr[] = {1, 2, 3}; int arr2[3]; std::copy(std::begin(arr), std::end(arr), std::begin(arr2)); }
29th Oct 2017, 8:18 AM
aklex
aklex - avatar
+ 2
@Baptiste I use iterators usually so that in case I decide to change the array for example to a vector, I don't have to change as much code :)
29th Oct 2017, 1:40 PM
aklex
aklex - avatar