back_inserter() in C++

back_inserter(): This function is available in the file stl_iterator.h. This function constructs the back-insert iterator that inserts the new element at the end of the given container.

Parameters: One parameter is required for this function.

arg: Container on which the iterator will insert new elements.

Syntax:

back_inserter(arg) = new value.

For Example:

vec  ={1,2,3}

back_inserter(vec) = 10 = > It insert 10 into vec.\

vec = {1,2,3,10}

Approach

C++

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

int main()
{
    vector<intvec = {123};

    back_inserter(vec= 10;

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

    return 0;
}


No comments:

Post a Comment