function template
<iterator>
std::advancetemplate <class InputIterator, class Distance> void advance (InputIterator& it, Distance n);
Advance iterator
Advances the iterator it by n element positions.If it is a random-access iterator, the function uses just once operator+
or operator-
. Otherwise, the function uses repeatedly the increase or decrease operator (operator++
or operator--
) until n elements have been advanced.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// advance example
#include <iostream> // std::cout
#include <iterator> // std::advance
#include <list> // std::list
int main () {
std::list<int> mylist;
for (int i=0; i<10; i++) mylist.push_back (i*10);
std::list<int>::iterator it = mylist.begin();
std::advance (it,5);
std::cout << "The sixth element in mylist is: " << *it << '\n';
return 0;
}
The sixth element in mylist is: 50
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4