back_insert_iterator::operator=
Assignment operator used to implement the output iterator expression *i = x.
back_insert_iterator<Container>& operator=(
typename Container::const_reference _Val
);
Parameters
- _Val
The value to be inserted into the container.
Return Value
A reference to the last element inserted at the back of the container
Remarks
The member function evaluates container.push_back(_Val).
Example
// back_insert_iterator_op_assign.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;
}
Output
The vector vec is: ( 1 2 3 ).
After the insertions, the vector vec becomes: ( 1 2 3 10 20 ).
Requirements
Header: <iterator>
Namespace: std