C++

'std::transform' Is Not a Member of 'std' Fix

std::transform lives in one header, <algorithm> - and almost no other common header pulls it in on the side, so this error does not hide: the textbook file that transforms a vector and prints it with std::cout gets it in full, and so does a lean file whose only include is <type_traits>. This guide pins down when the error appears, which probed headers do and do not cause it, and the one include that fixes it by specification.

Written November 30, 2026 · Tested with GCC 13.3.0 · 12 min read

By the end of this guide
  • The error: the include is missing
  • The textbook version fails too - the container and printing headers do not rescue it
  • Neighboring headers: which ones rescue it, which ones do not
  • The fix

Written November 30, 2026

Tested with GCC 13.3.0

What this guide is

std::transform is a function template defined in the header <algorithm>. It applies the given function to each element of a source range and stores the results in a destination range - the destination may be the source itself, so a range can be transformed in place.

Because the template lives in one specific header, 'transform' is not a member of 'std' has one common cause:

  • The #include <algorithm> line is missing, and no other header in the file pulls the name in transitively. For this error GCC prints no note naming <algorithm> and, in the contexts probed here, no suggestion at all, so the fix has to come from knowing the name's home, not from reading a note.

What makes this error hard to dodge is that almost no common header rescues it: in the sweep probed here, <vector>, <string>, and <iostream> do not pull the name in on this library version, so an ordinary file that transforms a vector and prints the result fails without <algorithm> - the textbook version is not spared. Of the headers probed, only <functional> rescues it. Each case is separated below.

The error: the include is missing

This program doubles each element of the array {1, 2, 3} in place using std::transform, but includes only <type_traits>:

C++
#include <type_traits>
int main() {
    int a[] = {1, 2, 3};
    std::transform(a, a + 3, a, [](int x) { return x * 2; });
    return a[0] == 2 && a[2] == 6 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 a_type_traits.cpp -o a_prog
a_type_traits.cpp: In function 'int main()':
a_type_traits.cpp:4:10: error: 'transform' is not a member of 'std'
    4 |     std::transform(a, a + 3, a, [](int x) { return x * 2; });
      |          ^~~~~~~~~

That is the whole output: one error, no note, no suggestion. The same program with no include at all fails the same way:

C++
int main() {
    int a[] = {1, 2, 3};
    std::transform(a, a + 3, a, [](int x) { return x * 2; });
    return a[0] == 2 && a[2] == 6 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 n_none.cpp -o n_none_prog
n_none.cpp: In function 'int main()':
n_none.cpp:3:10: error: 'transform' is not a member of 'std'
    3 |     std::transform(a, a + 3, a, [](int x) { return x * 2; });
      |          ^~~~~~~~~

The textbook version fails too - the container and printing headers do not rescue it

The version most often written first - transform a vector and print the elements with std::cout - fails without <algorithm>:

C++
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {1, 2, 3};
    std::transform(v.begin(), v.end(), v.begin(), [](int x) { return x * 2; });
    for (int x : v) std::cout << x << " ";
    std::cout << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 t_textbook.cpp -o t_prog
t_textbook.cpp: In function 'int main()':
t_textbook.cpp:5:10: error: 'transform' is not a member of 'std'
    5 |     std::transform(v.begin(), v.end(), v.begin(), [](int x) { return x * 2; });
      |          ^~~~~~~~~

Neither <vector> nor <iostream> pulls the name in transitively on this library version, and neither does the pair of them together, so the call fails in a textbook file just as it does in a lean one. No header except <algorithm> is required to declare std::transform. A program that uses std::transform includes <algorithm> rather than hoping for a rescue that, for this name, almost never comes.

Neighboring headers: which ones rescue it, which ones do not

In a sweep where each header below was compiled as the only header in a program that doubles the array {1, 2, 3} in place, the outcome is lopsided. These headers fail with the plain is not a member of 'std' error, with no note and no suggestion:

  • <type_traits>
  • <utility>
  • <numeric>
  • <limits>
  • <mutex>
  • <optional>
  • <cstring>
  • <vector>
  • <string>
  • <iostream>
  • <array>
  • <memory>

A file with no include at all fails the same way. Only one probed header rescues the program - it compiles and runs with no <algorithm> anywhere in the file:

  • <functional>

That rescue is a property of this library version, not a rule of the language - no header except <algorithm> is required to declare std::transform, and another library could leave it out of <functional> too.

This program includes only <utility>:

C++
#include <utility>
int main() {
    int a[] = {1, 2, 3};
    std::transform(a, a + 3, a, [](int x) { return x * 2; });
    return a[0] == 2 && a[2] == 6 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 s_utility.cpp -o s_utility_prog
s_utility.cpp: In function 'int main()':
s_utility.cpp:4:10: error: 'transform' is not a member of 'std'
    4 |     std::transform(a, a + 3, a, [](int x) { return x * 2; });
      |          ^~~~~~~~~

And this one includes only <numeric> - a header full of algorithms of its own, which still does not declare this one:

C++
#include <numeric>
int main() {
    int a[] = {1, 2, 3};
    std::transform(a, a + 3, a, [](int x) { return x * 2; });
    return a[0] == 2 && a[2] == 6 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 s_numeric.cpp -o s_numeric_prog
s_numeric.cpp: In function 'int main()':
s_numeric.cpp:4:10: error: 'transform' is not a member of 'std'
    4 |     std::transform(a, a + 3, a, [](int x) { return x * 2; });
      |          ^~~~~~~~~

The fix

Add the header:

C++
#include <algorithm>
#include <iostream>
int main() {
    int a[] = {1, 2, 3};
    std::transform(a, a + 3, a, [](int x) { return x * 2; });
    std::cout << a[0] << " " << a[1] << " " << a[2] << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 h_fixed.cpp -o h_prog
$ ./h_prog
2 4 6

One include, <algorithm>, declares the template. std::transform(a, a + 3, a, ...) writes each doubled value back over the array it read from, so the program prints 2 4 6.

The neighboring names: the whole header family fails too

The other names declared by <algorithm> fail with the same shape of error in the same lean context. std::sort, the sorting function in the same header, gets its own error, again with no header note and no suggestion:

C++
#include <type_traits>
int main() {
    int a[] = {3, 1, 2};
    std::sort(a, a + 3);
    return a[0] == 1 && a[2] == 3 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 b_sort.cpp -o b_prog
b_sort.cpp: In function 'int main()':
b_sort.cpp:4:10: error: 'sort' is not a member of 'std'
    4 |     std::sort(a, a + 3);
      |          ^~~~

And std::copy, the copying function in the same header, fails the same way:

C++
#include <type_traits>
int main() {
    int a[] = {1, 2, 3};
    int b[] = {0, 0, 0};
    std::copy(a, a + 3, b);
    return b[0] == 1 && b[2] == 3 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 c_copy.cpp -o c_prog
c_copy.cpp: In function 'int main()':
c_copy.cpp:5:10: error: 'copy' is not a member of 'std'
    5 |     std::copy(a, a + 3, b);
      |          ^~~~

One added include declares every one of these names: the transform, the sort, and the copy.

The neighboring names, fixed

With <algorithm> added, std::transform works on more than a plain array. The vector {1, 2, 3} prints as 2 4 6 after each element is doubled, and the string "veldica" becomes VELDICA - each character uppercased by ::toupper, the <cctype> function, whose argument is taken as unsigned char, as that function's rules require:

C++
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
#include <vector>
int main() {
    std::vector<int> v = {1, 2, 3};
    std::transform(v.begin(), v.end(), v.begin(), [](int x) { return x * 2; });
    std::cout << v[0] << " " << v[1] << " " << v[2] << "\n";
    std::string s = "veldica";
    std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return ::toupper(c); });
    std::cout << s << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 i_vector_string.cpp -o i_prog
$ ./i_prog
2 4 6
VELDICA

The <cctype> include is the one that declares ::toupper by specification, so it belongs in the file even though the same program also compiles without it on this library version - the name arrives transitively there, the same kind of unguaranteed rescue this guide warns about for std::transform itself.

Since C++20 the same header also declares std::ranges::transform, which can take the whole range instead of an iterator pair. With <algorithm> included it doubles the vector {1, 2, 3} and the program prints 2 4 6:

C++
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {1, 2, 3};
    std::ranges::transform(v, v.begin(), [](int x) { return x * 2; });
    std::cout << v[0] << " " << v[1] << " " << v[2] << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 j_ranges.cpp -o j_prog
$ ./j_prog
2 4 6

In the lean context - only <type_traits> and <vector> included - the ranges name fails with its own wording, 'transform' is not a member of 'std::ranges', and there GCC prints no note and no suggestion either:

C++
#include <type_traits>
#include <vector>
int main() {
    std::vector<int> v = {1, 2, 3};
    std::ranges::transform(v, v.begin(), [](int x) { return x * 2; });
    return v[0] == 2 && v[2] == 6 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 r_ranges_lean.cpp -o r_prog
r_ranges_lean.cpp: In function 'int main()':
r_ranges_lean.cpp:5:18: error: 'transform' is not a member of 'std::ranges'
    5 |     std::ranges::transform(v, v.begin(), [](int x) { return x * 2; });
      |                  ^~~~~~~~~

A different wording: the name without its qualifier

Including <algorithm> is not the only half of the name. This program includes the header but drops the std:: qualifier:

C++
#include <algorithm>
#include <iostream>
int main() {
    int a[] = {1, 2, 3};
    transform(a, a + 3, a, [](int x) { return x * 2; });
    for (int x : a) std::cout << x << " ";
    std::cout << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 g_unqualified.cpp -o g_prog
g_unqualified.cpp: In function 'int main()':
g_unqualified.cpp:5:5: error: 'transform' was not declared in this scope
    5 |     transform(a, a + 3, a, [](int x) { return x * 2; });
      |     ^~~~~~~~~
g_unqualified.cpp:5:5: note: suggested alternatives:
In file included from /usr/include/c++/13/algorithm:73,
                 from g_unqualified.cpp:1:
/usr/include/c++/13/pstl/glue_algorithm_defs.h:162:1: note:   'std::transform'
  162 | transform(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
      | ^~~~~~~~~
In file included from /usr/include/c++/13/algorithm:63:
/usr/include/c++/13/bits/ranges_algo.h:772:35: note:   'std::ranges::transform'
  772 |   inline constexpr __transform_fn transform{};
      |                                   ^~~~~~~~~

That wording - was not declared in this scope - is a different defect with a different fix: the header is present, the qualifier is not. Qualify the name as std::transform; adding includes does not bring the name out of namespace std. Note that the std::transform the suggestion points at is the execution-policy overload declared at that line, not the four-argument overload the call needs - the suggestion names the namespace, and the qualifier is the fix either way.

The exact rule

  • std::transform is declared by #include <algorithm>, and nowhere else by rule. In the sweep probed here, <type_traits>, <utility>, <numeric>, <limits>, <mutex>, <optional>, <cstring>, <vector>, <string>, <iostream>, <array>, and <memory> do not declare it, and neither does a file with no include at all.
  • 'transform' is not a member of 'std' means the <algorithm> include is missing and nothing else in the file pulled the name in - and, in the contexts probed here, GCC prints no note naming <algorithm> and no suggestion under it.
  • In the sweep probed here, <functional> is the only header besides <algorithm> that rescues std::transform transitively: a file whose only include is <functional> compiles and runs the call without <algorithm>. That is this library version's behavior, not a guarantee - no header is required to pull std::transform in.
  • std::sort and std::copy are declared by the same #include <algorithm>: in the programs shown here, which include only <type_traits> beside the use, each gets its own is not a member of 'std' error when that include is missing, with no header note and no suggestion.
  • std::ranges::transform is declared by the same #include <algorithm> since C++20: with the include it transforms a whole range passed as one argument, and in the lean context probed here it gets the error 'transform' is not a member of 'std::ranges' when that include is missing, again with no note and no suggestion.
  • 'transform' was not declared in this scope for an unqualified transform use is a different defect: qualify the name as std::transform - the include alone does not bring the name out of namespace std.

The fixes, ranked

  • First, check the include list of the file that names std::transform. If <algorithm> is not there, add it - that is the fix in the common case, and it holds whether or not the file happened to compile before through a transitive rescue.
  • Second, do not be reassured by the file compiling in a larger program. In the sweep here only <functional> rescues the name, so a missing <algorithm> usually shows itself at once - but where it does stay hidden, it surfaces when the code moves to a leaner file: add the include where the name is used.
  • Third, do not wait for a note naming the header. For this error, in the contexts probed here, GCC prints none - take the fix from the name's home header, <algorithm>.
  • Fourth, if the error says was not declared in this scope instead, fix the name's qualifier to std::transform as well.
  • Fifth, if the failing name is a neighboring one - sort or copy - the same added include fixes it: every one of those names shares the header, and none of them gets a header note in the programs here either.

Which fix for which cause

  • #include <algorithm> missing, std::transform used in a file whose only include is <type_traits>, <utility>, <numeric>, <limits>, <mutex>, <optional>, <cstring>, <vector>, <string>, <iostream>, <array>, or <memory>, or that includes nothing: the message is 'transform' is not a member of 'std', with no header note and no suggestion - add #include <algorithm>.
  • std::transform used with only <functional> included: no error on this library version - add #include <algorithm> anyway, because the rescue is not guaranteed.
  • std::sort or std::copy used without <algorithm> in the lean context: the message names that name, with no header note - add #include <algorithm>.
  • transform used without the std:: qualifier, <algorithm> included: the message is 'transform' was not declared in this scope - qualify the name as std::transform.

Checklist

  • Check the include list of the file that names the transform, not just the project. The include must be in that file, or in a header that file includes directly by design.
  • Do not wait for a note naming the header. For this error, in the contexts probed here, GCC prints none - take the fix from the name's home header, <algorithm>, instead.
  • Do not be reassured by <iostream> or <vector> being present. In the sweep here neither rescues std::transform, so their presence says nothing about whether <algorithm> is there - and a file rescued by <functional> elsewhere can still be missing it.
  • One header per name the file uses: std::vector comes from <vector>, std::string from <string>, and ::toupper from <cctype>, even in a program whose subject is the transform - and std::transform comes from <algorithm> in return.
  • After the fix, confirm the program runs, not just that it compiles: the fixed programs here print 2 4 6 for the doubled array, 2 4 6 and VELDICA for the vector and the string, and 2 4 6 for the ranges transform.

Sources

  • cppreference, std::transform — for std::transform being a function template defined in <algorithm> that applies the given function to the elements of a source range and stores the results in a destination range.
  • cppreference, Standard library header <algorithm> — for <algorithm> being the header that declares the std::transform, std::sort, and std::copy function templates.
  • cppreference, std::ranges::transform — for std::ranges::transform being an algorithm function object defined in <algorithm> since C++20 that applies a function to the elements of a range, with an overload that takes the whole range as one argument.
  • cppreference, std::toupper — for toupper being a <cctype> function that converts a character to uppercase, and for its argument needing to be representable as unsigned char.

Keep Exploring