Guest User

Untitled

a guest
Jan 18th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. // with stl
  2. int a[] = { 1, 2, 3, 4, 5 };
  3. int b[5];
  4. std::copy(std::begin(a),std::end(a),std::begin(b));
  5. for(auto e:b) cout << e << " "; // 1 2 3 4 5
  6.  
  7. // array container (C++11)
  8. std::array<int,5> arr = { 1, 2, 3, 4, 5 };
  9. std::array<int,5> copy;
  10. copy = arr;
  11. arr[0] = 100;
  12. for(auto e:copy) cout << e << " "; // 1 2 3 4 5
  13.  
  14. // C style - memcpy
  15. int arr[] = {1,2,3,4,5};
  16. int copy[5];
  17. int len = sizeof(arr) / sizeof(arr[0]);
  18. // void* memcpy(void* destination,const void* source,size_t num);
  19. memcpy(copy, arr, len * sizeof(int));
  20. for(auto e:copy) cout<< e << " "; // 1 2 3 4 5
  21.  
  22. // C style - memmove
  23. int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
  24. memmove(arr + 3, arr + 1, sizeof(int) * 5);
  25. for(auto e:arr) cout<< e << " "; // 1 2 3 2 3 4 5 6
Add Comment
Please, Sign In to add comment