Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // with stl
- int a[] = { 1, 2, 3, 4, 5 };
- int b[5];
- std::copy(std::begin(a),std::end(a),std::begin(b));
- for(auto e:b) cout << e << " "; // 1 2 3 4 5
- // array container (C++11)
- std::array<int,5> arr = { 1, 2, 3, 4, 5 };
- std::array<int,5> copy;
- copy = arr;
- arr[0] = 100;
- for(auto e:copy) cout << e << " "; // 1 2 3 4 5
- // C style - memcpy
- int arr[] = {1,2,3,4,5};
- int copy[5];
- int len = sizeof(arr) / sizeof(arr[0]);
- // void* memcpy(void* destination,const void* source,size_t num);
- memcpy(copy, arr, len * sizeof(int));
- for(auto e:copy) cout<< e << " "; // 1 2 3 4 5
- // C style - memmove
- int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
- memmove(arr + 3, arr + 1, sizeof(int) * 5);
- for(auto e:arr) cout<< e << " "; // 1 2 3 2 3 4 5 6
Add Comment
Please, Sign In to add comment