Is there a better way of printing a vector in reverse order then this:
#include
#include
#include
using namespace
There are many ways to do this.I will just explain one, more can be seen in this link.
Using constant reverse iterator(crbegin):
Reverse iterators iterate backward i.e increasing them moves them towards the beginning of the container.
To check if we have reached beginning, we can use the iterator variable(x in my case) to compare with crend (returns the starting of the vector).Remember everything is reverse here!
following is a simple implementation:
for(auto x = vec.crbegin() ; x!=vec.crend() ; x++){
cout<<*x<<" ";
}