c++ for each loop reverse code example
Example: 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];
}
// 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];
}