advance (STL Samples)
사용 하는 방법을 보여 줍니다 있는 미리 Visual C++에서 표준 템플릿 라이브러리 (STL) 함수.
template<class InIt, class Dist>
void advance(
InIt& it,
Dist n
);
설명
[!참고]
프로토타입에 클래스/매개 변수 이름은 헤더 파일에서 버전이 일치 하지 않습니다.일부 가독성을 높이기 위해 수정 되었습니다.
미리 STL 함수 두 개의 매개 변수를 받아들입니다.
InIt -발전 하는 반복기입니다.
Dist- 요소에 반복기를 증가 시킬 수 있습니다.
미리 함수 STL 반복기를 앞으로 이동 n 번입니다.반복기는 임의 액세스 반복기 형식인 경우 함수 계산으로 반복기 + = n.그렇지 않으면 계산 하 여 각 증분 수행: + + 반복기입니다.반복기는 입력 또는 전달 반복기 형식인 경우 n 음수일 수 없습니다.
예제
// Advance.cpp
// compile with: /EHsc
#pragma warning (disable:4786)
#include <iostream>
#include <string>
#include <list>
using namespace std ;
typedef list<string> STRLIST;
int main() {
STRLIST List;
STRLIST::iterator iList;
STRLIST::difference_type dTheDiff;
List.push_back("A1");
List.push_back("B2");
List.push_back("C3");
List.push_back("D4");
List.push_back("E5");
List.push_back("F6");
List.push_back("G7");
// Print out the list
iList=List.begin();
cout << "The list is: ";
for (int i = 0; i < 7 ; i++, iList++)
cout << *iList << " ";
// Initialize to the first element"
iList=List.begin();
cout << "\n\nAdvance to the 3rd element." << endl;
advance(iList,2);
cout << "The element is " << *iList << endl;
dTheDiff = distance( List.begin(), iList);
}
Output
The list is: A1 B2 C3 D4 E5 F6 G7
Advance to the 3rd element.
The element is C3
요구 사항
헤더: <iterator>