inserter
A helper template function that lets you use inserter(_Cont,_Where) instead of insert_iterator<Container>(_Cont,_Where).
template<class Container>
insert_iterator<Container> inserter(
Container& _Cont,
typename Container::iterator _Where
);
매개 변수
_Cont
새 요소가 추가 되는 컨테이너입니다._Where
삽입 지점을 찾는 반복기입니다.
설명
The template function returns insert_iterator::insert_iterator<Container>(_Cont, _Where).
예제
// iterator_inserter.cpp
// compile with: /EHsc
#include <iterator>
#include <list>
#include <iostream>
int main( )
{
using namespace std;
int i;
list <int>::iterator L_Iter;
list<int> L;
for (i = 2 ; i < 5 ; ++i )
{
L.push_back ( 10 * i );
}
cout << "The list L is:\n ( ";
for ( L_Iter = L.begin( ) ; L_Iter != L.end( ); L_Iter++ )
cout << *L_Iter << " ";
cout << ")." << endl;
// Using the template version to insert an element
insert_iterator<list <int> > Iter( L, L.begin ( ) );
*Iter = 1;
// Alternatively, using the member function to insert an element
inserter ( L, L.end ( ) ) = 500;
cout << "After the insertions, the list L is:\n ( ";
for ( L_Iter = L.begin( ) ; L_Iter != L.end( ); L_Iter++)
cout << *L_Iter << " ";
cout << ")." << endl;
}
요구 사항
헤더: <iterator>
네임 스페이스: std