Advertisement
peterzig

[C++] Static Array increment vs. std::iota

Oct 12th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <numeric>
  4.  
  5. using namespace std;
  6.  
  7. void f(int *p, size_t l)
  8. {
  9.     for(size_t i = 0; i<l; ++i)
  10.     {
  11.         p[i] = i;
  12.         printf("%d", p[i]);
  13.     }
  14. }
  15.  
  16. int main()
  17. {
  18.    
  19.   int my_array[5];
  20.   //f(my_array, 5);
  21.   iota(my_array,my_array +5, 0);
  22.   for(int i = 0; i < 5; ++i)
  23.   {
  24.       printf("%d\n",my_array[i]);
  25.   }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement