Yes, since C++11 there are the two methods you are looking for called std::prev
and std::next
. You can find them in the iterator library.
Example from cppreference.com
#include <iostream>
#include <iterator>
#include <vector>
int main()
{
std::list<int> v{ 3, 1, 4 };
auto it = v.begin();
auto nx = std::next(it, 2);
std::cout << *it << ' ' << *nx << '
';
}
Output:
3 4
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…