| back_inserter |
function template |
template <class Container>
back_insert_iterator<Container> back_inserter (Container& x); |
<iterator> |
Construct a back insert iterator
This function generates a back insert iterator for a container.
A back insert iterator is a special type of output iterator specifically designed to allow algorithms that usually overwrite elements (such as copy) to instead insert new elements at the end of the container.
Parameters
- x
- Container for which the back insert iterator is constructed.
Return value
A
back_insert_iterator that inserts elements at the end of container
x.
Example
// back_inserter example
#include <iostream>
#include <iterator>
#include <vector>
using namespace std;
int main () {
vector<int> firstvector, secondvector;
for (int i=1; i<=5; i++)
{ firstvector.push_back(i); secondvector.push_back(i*10); }
copy (secondvector.begin(),secondvector.end(),back_inserter(firstvector));
vector<int>::iterator it;
for ( it = firstvector.begin(); it!= firstvector.end(); ++it )
cout << *it << " ";
cout << endl;
return 0;
} |
Output:
See also
| inserter | Construct an insert iterator (function template) |