back_insert_iterator() in C++

back_insert_iterator(): This function is available in the file stl_iterator.h. Turns assignment into insertion. These are output iterators, constructed from a container-of-T. This returns a back_insert_iterator for the parameter container or returns a reference to the element inserted at the back of the container.

Parameters: One parameter is required.

 _Cont: The container that the back_insert_iterator is to insert an element into. 

Syntax:

back_insert_iterator<vectordata_type>>::container_type arr = vec

For Example:

vec = {1,2,3,4}

back_insert_iterator<vector<int>>::container_type arr = vec

=> arr  ={ 1,2,3,4}

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<intvec = {1234};
    back_insert_iterator<vector<int>>::container_type arr = vec;

      for (int i = 0i < arr.size(); i++)
        cout << arr[i] << " ";

    return 0;
}


No comments:

Post a Comment