![]() |
VOOZH | about |
In C++, transform() is a built-in STL function used to apply the given operation to a range of elements and store the result in another range. Let’s take a look at a simple example that shows the how to use this function:
2 6 7 9
Explanation: The function adds 1 to all elements of vector v1 and store the result in another vector v2.
This article covers the syntax, usage, and common examples of transform() method in C++:
Table of Content
The transform() function is defined inside <algorithm> header file has 2 implementations:
transform(first, last, res, op1); // For Unary Operation
transform(first, last, first1, res, op2); // For Binary Operation
The transform() function can be used to perform a wide variety of operations on the given range of operations. The following examples demonstrates some of the common examples that illustrates the use of this function.
1 2 3 4 5
geeksforgeeks
Explanation: The transform() function converts all character of string s to lowercase and store the resultant string back to string s.
7 11 16 18 53
Explanation: The transform() function adds all elements of vector v1 and v2 with one another and store the resultant vector in v.