std::advance in C++
std::advance advances the iterator ‘it’ by n element positions.
template void advance (InputIterator& it, Distance n); it : Iterator to be advanced n : Number of element positions to advance. This shall only be negative for random-access and bidirectional iterators. Return type : None.
Motivation problem : A vector container is given. Task is to print alternate elements.
Input : 10 40 20 50 80 70 Output : 10 20 80
0 10 20 30 40 50 60 70 80 90 0 20 40 60 80
This article is contributed by Rohit Thapliyal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.