back_inserter
지정된 컨테이너 뒤에 있는 요소를 삽입할 수 있는 반복기를 만듭니다.
template<class Container>
back_insert_iterator<Container> back_inserter(
Container& _Cont
);
매개 변수
- _Cont
The container into which the back insertion is to be executed.
반환 값
A back_insert_iterator associated with the container object _Cont.
설명
Within the Standard Template Library, the argument must refer to one of the three sequence containers that have the member function push_back: deque Class, list Class, or vector Class.
예제
// iterator_back_inserter.cpp
// compile with: /EHsc
#include <iterator>
#include <vector>
#include <iostream>
int main( )
{
using namespace std;
int i;
vector<int> vec;
for ( i = 0 ; i < 3 ; ++i )
{
vec.push_back ( i );
}
vector <int>::iterator vIter;
cout << "The initial vector vec is: ( ";
for ( vIter = vec.begin ( ) ; vIter != vec.end ( ); vIter++)
cout << *vIter << " ";
cout << ")." << endl;
// Insertions can be done with template function
back_insert_iterator<vector<int> > backiter ( vec );
*backiter = 30;
backiter++;
*backiter = 40;
// Alternatively, insertions can be done with the
// back_insert_iterator member function
back_inserter ( vec ) = 500;
back_inserter ( vec ) = 600;
cout << "After the insertions, the vector vec is: ( ";
for ( vIter = vec.begin ( ) ; vIter != vec.end ( ); vIter++ )
cout << *vIter << " ";
cout << ")." << endl;
}
요구 사항
헤더: <iterator>
네임스페이스: std