In this blog post we will learn how to change value in vector during insertion using std::transform. For example let us assume we need to insert values from vector A to vector B.

Let us see below example using std:transform

#include <iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main()
{
    vector<int> A ={ 1, 2, 3 };
    vector<int> B ={ 4, 5, 3 };
    //A.insert(end(A), begin(B), end(B));
    transform(B.begin(), B.end(), back_inserter(A), std::negate<int>());
    for(auto value:A)
    {
        cout << value <<" ";
    }
    return 0;
}

Output:

1 2 3 4 5 3 -4 -5 -3



Related Contents to follow