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.
- Synchronous Chatting Application using C++ boost::asio
- C/C++ For loop with Examples
- How to input a comma separated string in C++?
- Program to Parse a comma separated string in C++
- Difference between Private and Protected in C++ with Example
- Difference between Inheritance and Polymorphism
- Difference between Single and Multiple Inheritance in C++
- Difference between Abstraction and Encapsulation in C++
- return statement in C/C++ with Examples
- How to implement our own Vector Class in C++?
- Web Programming in C++
- C++ Program to print an Array using Recursion
- Storage Classes in C++ with Examples
- fill_n() function in C++ STL with examples
- fill() function in C++ STL with examples