C++

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

std::reverse lives in one header, <algorithm> - and almost nothing pulls it in on the side, so this error shows up even in ordinary textbook files: reversing a vector and printing it with std::cout fails the same way. 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 common 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::reverse is a function template defined in the header <algorithm>. It reverses the order of the elements in the range [first, last) in place, swapping each pair of corresponding elements.

Because the template lives in one specific header, 'reverse' 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 no suggestion, 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: <iostream>, <vector>, and <string> do not pull the name in on this library version, so even an ordinary file that reverses a vector and prints the result fails without <algorithm>. Of the headers probed here, only <functional> rescues it. Each case is separated below.

The error: the include is missing

This program reverses the array {1, 2, 3} with std::reverse, but includes only <type_traits>:

C++
#include <type_traits>
int main() {
    int a[] = {1, 2, 3};
    std::reverse(a, a + 3);
    return a[0] == 3 && a[2] == 1 ? 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: 'reverse' is not a member of 'std'
    4 |     std::reverse(a, a + 3);
      |          ^~~~~~~

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::reverse(a, a + 3);
    return a[0] == 3 && a[2] == 1 ? 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: 'reverse' is not a member of 'std'
    3 |     std::reverse(a, a + 3);
      |          ^~~~~~~

The textbook version fails too - the common headers do not rescue it

The version most often written first - reverse 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::reverse(v.begin(), v.end());
    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: 'reverse' is not a member of 'std'
    5 |     std::reverse(v.begin(), v.end());
      |          ^~~~~~~

What happened: neither <iostream> nor <vector> pulls the name in transitively on this library version, so the call fails in a textbook file exactly as it does in a lean one. Dropping <vector> changes nothing - a file with only <iostream> that reverses a plain array gets the same error at the same shape of position. No header except <algorithm> is required to declare std::reverse, and on this library version the ordinary printing and container headers do not happen to do it either. A program that uses std::reverse includes <algorithm>.

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 reverses the array {1, 2, 3}, the outcome splits - and the failing side is the long one. 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>
  • <cmath>

A file with no include at all fails the same way. Of the headers probed here, only this one 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::reverse, 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::reverse(a, a + 3);
    return a[0] == 3 && a[2] == 1 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 a_utility.cpp -o a_utility_prog
a_utility.cpp: In function 'int main()':
a_utility.cpp:4:10: error: 'reverse' is not a member of 'std'
    4 |     std::reverse(a, a + 3);
      |          ^~~~~~~

And this one includes only <limits>:

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

The fix

Add the header:

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

One include, <algorithm>, declares the template. std::reverse(a, a + 3) reverses the array in place, so the program prints the elements back to front: 3 2 1.

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::reverse_copy - the function template that copies a range into a destination in reverse order, leaving the source unchanged - gets its own error, again with no header note:

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

std::rotate - the function template that performs a left rotation on a range, so the element at middle moves to the front - fails the same way:

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

And std::sort, the sorting function in the same header, fails the same way in this lean context:

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 d_sort.cpp -o d_prog
d_sort.cpp: In function 'int main()':
d_sort.cpp:4:10: error: 'sort' is not a member of 'std'
    4 |     std::sort(a, a + 3);
      |          ^~~~

So does std::fill, the function template that assigns one value to every element in a range:

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

One added include declares every one of these names: the in-place reversal, the reversed copy, the rotation, the sort, and the fill.

The neighboring names, fixed

With <algorithm> added, std::reverse works on more than a plain array. The vector {1, 2, 3, 4} prints back to front as 4 3 2 1, and the string "veldica" prints reversed as acidlev:

C++
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
int main() {
    std::vector<int> v = {1, 2, 3, 4};
    std::reverse(v.begin(), v.end());
    for (int x : v) std::cout << x << " ";
    std::cout << "\n";
    std::string s = "veldica";
    std::reverse(s.begin(), s.end());
    std::cout << s << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 i_vector_string.cpp -o i_prog
$ ./i_prog
4 3 2 1
acidlev

And std::reverse_copy fills the destination with 3 2 1 while the source stays 1 2 3 - the copy is reversed, the original is not - while std::rotate with the middle at the second element brings that element to the front, printing 2 3 1:

C++
#include <algorithm>
#include <iostream>
int main() {
    int a[] = {1, 2, 3};
    int b[] = {0, 0, 0};
    std::reverse_copy(a, a + 3, b);
    for (int x : b) std::cout << x << " ";
    std::cout << "\n";
    for (int x : a) std::cout << x << " ";
    std::cout << "\n";
    int c[] = {1, 2, 3};
    std::rotate(c, c + 1, c + 3);
    for (int x : c) std::cout << x << " ";
    std::cout << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 j_reverse_copy_rotate.cpp -o j_prog
$ ./j_prog
3 2 1
1 2 3
2 3 1

Since C++20 the same header also declares std::ranges::reverse, which takes the whole range instead of an iterator pair. With <algorithm> included it reverses the vector {1, 2, 3} and the program prints 3 2 1; in the lean context - only <type_traits> and <vector> included - it fails with its own wording, 'reverse' is not a member of 'std::ranges', because the missing include is the same one.

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};
    reverse(a, a + 3);
    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: 'reverse' was not declared in this scope
    5 |     reverse(a, a + 3);
      |     ^~~~~~~
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:249:1: note:   'std::reverse'
  249 | reverse(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __last);
      | ^~~~~~~
In file included from /usr/include/c++/13/algorithm:63:
/usr/include/c++/13/bits/ranges_algo.h:1292:33: note:   'std::ranges::reverse'
 1292 |   inline constexpr __reverse_fn reverse{};
      |                                 ^~~~~~~

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::reverse; adding includes does not bring the name out of namespace std. Note that the std::reverse the suggestion points at is the execution-policy overload declared at that line, not the two-iterator overload the call needs - the suggestion names the namespace, and the qualifier is the fix either way.

The exact rule

  • std::reverse 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 <cmath> do not declare it, and neither does a file with no include at all.
  • 'reverse' 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, only <functional> rescues std::reverse 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::reverse in.
  • std::reverse_copy, std::rotate, std::sort, and std::fill 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.
  • std::ranges::reverse is declared by the same #include <algorithm> since C++20: with the include it reverses a whole range passed as one argument, and in the lean context probed here it gets the error 'reverse' is not a member of 'std::ranges' when that include is missing.
  • 'reverse' was not declared in this scope for an unqualified reverse use is a different defect: qualify the name as std::reverse - 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::reverse. 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 expect the textbook includes to save the file. In the sweep here <iostream>, <vector>, and <string> do not rescue the name - a file that reverses and prints still needs <algorithm> itself.
  • 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::reverse as well.
  • Fifth, if the failing name is a neighboring one - reverse_copy, rotate, sort, or fill - 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::reverse used in a file whose only include is <type_traits>, <utility>, <numeric>, <limits>, <mutex>, <optional>, or <cstring>, or that includes nothing: the message is 'reverse' is not a member of 'std', with no header note and no suggestion - add #include <algorithm>.
  • std::reverse used with only <vector>, <string>, <iostream>, <array>, or <cmath> included: the same error on this library version - these headers do not rescue the name, so add #include <algorithm>.
  • std::reverse used with only <functional> included: no error on this library version - add #include <algorithm> anyway, because the rescue is not guaranteed.
  • std::reverse_copy, std::rotate, std::sort, or std::fill used without <algorithm> in the lean context: the message names that name, with no header note - add #include <algorithm>.
  • reverse used without the std:: qualifier, <algorithm> included: the message is 'reverse' was not declared in this scope - qualify the name as std::reverse.

Checklist

  • Check the include list of the file that names the reversal, 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::reverse at all - the missing <algorithm> is exposed in textbook files, not just lean ones.
  • One header per name the file uses: std::vector comes from <vector> and std::string from <string>, even in a program whose subject is the reversal - and std::reverse comes from <algorithm> in return.
  • After the fix, confirm the program runs, not just that it compiles: the fixed programs here print 3 2 1 for the reversed array, 4 3 2 1 and acidlev for the vector and the string, and 3 2 1, 1 2 3, and 2 3 1 for the reversed copy, the untouched source, and the rotation.
  • 'std::sort' Is Not a Member of 'std' Fix - the same missing-include shape for the sorting function in <algorithm>, a neighboring name in the same header that fails alongside this guide's name in the lean context.
  • 'std::find' Is Not a Member of 'std' Fix - the same missing-include shape for the search function in <algorithm>; there, as here, the ordinary container and printing headers do not rescue the name.
  • 'std::max' Is Not a Member of 'std' Fix - the same missing-include shape for the greater-of-two function in <algorithm>; there, many common headers rescue the name transitively, here almost none do.

Sources

  • cppreference, std::reverse — for std::reverse being a function template defined in <algorithm> that reverses the order of the elements in the range [first, last) by swapping each pair of corresponding elements, and for std::ranges::reverse being its C++20 ranges counterpart in the same header.
  • cppreference, Standard library header <algorithm> — for <algorithm> being the header that declares the std::reverse, std::reverse_copy, std::rotate, std::sort, and std::fill function templates.
  • cppreference, std::reverse_copy — for std::reverse_copy being a function template defined in <algorithm> that copies the elements from the source range [first, last) to the destination range beginning at d_first in reverse order.
  • cppreference, std::rotate — for std::rotate being a function template defined in <algorithm> that performs a left rotation on the range [first, last), placing the elements in [first, middle) after the elements in [middle, last) while preserving the order within each part.
  • cppreference, std::fill — for std::fill being a function template defined in <algorithm> that assigns the given value to all elements in the range [first, last).

Keep Exploring