inserter() in C++

inserter(): This function is available in the file stl_iterator.h.This function returns an instance of insert_iterator working on __x. This wrapper function helps in creating insert_iterator instances. Typing the name of the iterator requires knowing the precise full type of the container, which can be tedious and impedes generic programming. This function permits you to make the most of automatic template parameter deduction, making the compiler match the proper types for you.

Parameters: Two parameters are required for this function.

 __x – A container of arbitrary type.

 __i – An iterator into the container. 

Syntax:

inserter(__x, __i)

Approach

C++

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

int main()
{
    vector<intvec = {11030};
    vector<intarr = {4560};

    copy(arr.begin(), arr.end(), inserter(vecvec.begin()));

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

        return 0;
}


No comments:

Post a Comment