void rev(string& str)
{
for (auto i = str.end() -1; i != str.begin() -1; i--)
cout << *i;
cout << '\n';
}
The code above works on my system however str.begin() -1
invokes undefined behaviour as per the standard. So what is the idiomatic way of reverse traversal using iterator's but not reverse_iterator's?
CodePudding user response:
This works
for (auto i = str.end(); i != str.begin(); )
{
--i;
...
}