#include<iostream>
#include <vector>
int main()
{
std::vector<char> vec(26);///init vector of size 26 to contain a-z letters
// fill vector values from a to z
std::cout << "print in order" << std::endl;
for (auto& elem : vec)
{
//elem is the value of the organ in the vector
// if the current index is needed:
auto i = &elem - &vec[0];
elem = 'a' +i;
std::cout << elem << " ";
}
//print in reverse order
std::cout << "print in reverse order" << std::endl;
for (std::vector<int>::reverse_iterator rit=vec.rbegin();rit!=vec.rend();rit++)
std::cout << *rit << " ";
return 0;
}
// for (std::vector<int>::reverse_iterator rit=vec.rbegin();rit!=vec.rend();rit++)
for (std::vector<char>::reverse_iterator rit=vec.rbegin();rit!=vec.rend();rit++)
Use auto to avoid silly errors like this: for( auto rit = vec.rbegin() ; rit != vec.rend() ; ++rit )