How to use iterator from the end to the beginning (backwards) of array object in C++

1 Answer

0 votes
#include <iostream>
#include <array>
 
int main () {
    std::array<int, 5> arr;
 
    for (int i = 0; i < 5; i++) arr.at(i) = i + 1;

    for (auto it = arr.crbegin(); it != arr.crend(); it++)
        std::cout << *it << ", ";
 
  return 0;
}
 
 
 
/*
run:
 
5, 4, 3, 2, 1, 
  
*/

 



answered Jul 28, 2020 by avibootz

Related questions

...