Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- template <typename T>
- int copy(T* srcB, T* srcE, T* destB, T* destE)
- {
- int copyCount{ 0 };
- while (destB != destE and srcB != srcE)
- {
- *destB++ = *srcB++;
- ++copyCount;
- }
- return copyCount;
- }
- template <typename T>
- void print(T* begin, T* end)
- {
- while (begin != end )
- {
- std::cout << *begin << ' ';
- ++begin;
- }
- std::cout << '\n';
- }
- int main()
- {
- const int arrSize{10};
- int arr[arrSize]{1,2,3,4,5,6,7,8,9,10};
- int arr1[arrSize]{};
- char str[arrSize]{'a','b','c','d','e','f','g','h','i','j'};
- char str1[arrSize]{};
- copy(arr,arr+arrSize,arr1,arr1+arrSize);
- print(arr1,arr1+arrSize);
- copy(str,str+arrSize,str1,str1+arrSize);
- print(str1,str1+arrSize);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement