std::next
来自cppreference.com
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
Defined in header <iterator>
|
||
template< class ForwardIt > ForwardIt next( ForwardIt it, |
(C++11 起) | |
返回的nth的继任者的迭代器it.
Original:
Return the nth successor of iterator it.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目录 |
[编辑] 参数
it | - | iterater“
Original: an iterater' The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
n | - | 前进的元素的数量
Original: number of elements to advance The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Type requirements | ||
-ForwardIt must meet the requirements of ForwardIterator .
|
[编辑] 返回值
nth继任者的迭代器it.
Original:
The nth successor of iterator it.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 可能的实现
template<class ForwardIt> ForwardIt next(ForwardIt it, typename std::iterator_traits<ForwardIt>::difference_type n = 1) { std::advance(it, n); return it; } |
[编辑] 为例
#include <iostream> #include <iterator> #include <vector> int main() { std::vector<int> v{ 3, 1, 4 }; auto it = v.begin(); auto nx = std::next(it, 2); std::cout << *it << ' ' << *nx << '\n'; }
Output:
3 4
[编辑] 另请参阅
(C++11) |
减一个迭代器 Original: decrement an iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (函数) |
给定距离的迭代器 Original: advances an iterator by given distance The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (函数) |