I have a smart pointer defined like this
auto ptr = make_shared<int[]>(5);
and another array
int arr[] = {1,2,3,4,5};
I want to copy data in arr to ptr, I tried using this
memcpy(ptr.get(), arr, 5 * sizeof(int))
But when I try printing like this
for (int i = 0; i < 5; i++) {
std::cout<<ptr[i]<<std::endl;
}
I get
malloc(): corrupted top size
Process finished with exit code 134
(interrupted by signal 6: SIGABRT)
Is there something wrong with the ptr initialization ?