Answers for "c++ foreach backwards"

C++
6

for loop reverse C++

// Using iterators
for (auto it = s.crbegin() ; it != s.crend(); ++it) {
  std::cout << *it;
}

// Naive
for (int i = s.size() - 1; i >= 0; i--) {
  std::cout << s[i];
}
Posted by: Guest on October-04-2020
1

c++ loop through array backwards

int [] a = {1,2,3};

for(int i = a.size()-1;i>=0;i--)
  	cout<<a[i]<<" ";
cout<<endl;
Posted by: Guest on April-19-2022

Browse Popular Code Answers by Language