back_inserter

创建可插入元素在指定的容器的返回一个迭代。

template<class Container>
   back_insert_iterator<Container> back_inserter(
      Container& _Cont
   );

参数

  • _Cont
    返回插入要执行的容器。

返回值

back_insert_iterator 与容器对象 _Cont。

备注

在标准模板库中,参数必须引用具有成员函数 push_back三个序列容器之一:、向量、双端队列选件类列表选件类检测选件类

示例

// 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

请参见

参考

标准模板库