back_insert_iterator::back_insert_iterator
建構可在容器的最後一個項目之後插入項目的 back_insert_iterator 。
explicit back_insert_iterator(
Container& _Cont
);
參數
- _Cont
容器 back_insert_iterator 是將項目插入。
傳回值
參數的 back_insert_iterator 容器。
範例
// back_insert_iterator_back_insert_iterator.cpp
// compile with: /EHsc
#include <iterator>
#include <vector>
#include <iostream>
int main( )
{
using namespace std;
int i;
vector<int> vec;
for ( i = 1 ; i < 4 ; ++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 with member function
back_inserter ( vec ) = 40;
back_inserter ( vec ) = 50;
// Alternatively, insertions can be done with template function
back_insert_iterator<vector<int> > backiter ( vec );
*backiter = 600;
backiter++;
*backiter = 700;
cout << "After the insertions, the vector vec is: ( ";
for ( vIter = vec.begin ( ) ; vIter != vec.end ( ); vIter++)
cout << *vIter << " ";
cout << ")." << endl;
}
需求
標題: <iterator>
命名空間: std