How to increment an iterator by 2?


Question

Can anybody tell me how to increment the iterator by 2?

iter++ is available - do I have to do iter+2? How can I achieve this?

1
62
9/7/2015 11:28:05 AM

std::advance( iter, 2 );

This method will work for iterators that are not random-access iterators but it can still be specialized by the implementation to be no less efficient than iter += 2 when used with random-access iterators.

93
8/28/2013 7:54:23 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon