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.
- Implementing upper_bound() and lower_bound() for Ordered Set in C++
- How to flatten a Vector of Vectors or 2D Vector in C++
- Queue of Pairs in C++ STL with Examples
- Remove odd frequency characters from the string
- Different ways to use Const with Reference to a Pointer in C++
- std::to_address in C++ with Examples
- Program to create Custom Vector Class in C++
- std::is_trivially_copy_constructible in C/C++
- Difference between Python and C++
- tgamma() method in C/C++ with Examples
- boost::type_traits::is_array Template in C++
- boost is_pointer template in C++
- Stack of Pair in C++ STL with Examples
- Modulo Operator (%) in C/C++ with Examples
- fpclassify() method in C/C++ with Examples