共用方式為


back_insert_iterator::operator*

Dereferencing operator used to implement the output iterator expression *i = x.

back_insert_iterator<Container>& operator*( );

Return Value

A reference to the element inserted at the back of the container.

Remarks

Used to implement the output iterator expression *Iter = value. If Iter is an iterator that addresses an element in a sequence, then *Iter = value replaces that element with value and does not change the total number of elements in the sequence.

Example

// back_insert_iterator_back_insert.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 vector vec is: ( ";
   for ( vIter = vec.begin ( ) ; vIter != vec.end ( ); vIter++)
      cout << *vIter << " ";
   cout << ")." << endl;

   back_insert_iterator<vector<int> > backiter ( vec );
   *backiter = 10;
   backiter++;      // Increment to the next element
   *backiter = 20;
   backiter++;

   cout << "After the insertions, the vector vec becomes: ( ";
   for ( vIter = vec.begin ( ) ; vIter != vec.end ( ); vIter++)
      cout << *vIter << " ";
   cout << ")." << endl;
}
The vector vec is: ( 1 2 3 ).
After the insertions, the vector vec becomes: ( 1 2 3 10 20 ).

Requirements

Header: <iterator>

Namespace: std

See Also

Reference

back_insert_iterator Class

Standard Template Library

Other Resources

back_insert_iterator Members