0
(C++) Copying Arrays
If I make an array, what's the easiest way to make an exact copy of that array?
3 odpowiedzi
+ 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
+ 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));
}
+ 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 :)