C++

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

std::find lives in one header, <algorithm> - and unlike some neighboring names, almost nothing else pulls it in. A file that searches a std::vector and prints with std::cout still fails without it, because <vector> and <iostream> do not declare the range std::find. 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 · 14 min read

By the end of this guide
  • The error: the include is missing
  • The textbook version fails too - with a different wording
  • 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::find is a function template defined in the header <algorithm>. It returns an iterator to the first element in the range [first, last) that is equal to the given value, using operator==, or last if there is no such element.

Because the template lives in one specific header, 'find' 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. Almost no common header does: in the sweep probed below, only <functional> rescues the call. For this error in a lean file GCC prints no note naming <algorithm>, so the fix has to come from knowing the name's home, not from reading a note.

The error therefore shows up in ordinary files, not just lean ones - including the textbook version that searches a std::vector and prints with std::cout. Each case is separated below.

The error: the include is missing

This program searches a raw array for the value 2, but includes only <type_traits>:

C++
#include <type_traits>
int main() {
    int values[] = {5, 2, 8};
    auto it = std::find(values, values + 3, 2);
    return it == values + 3 ? 1 : 0;
}
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:20: error: 'find' is not a member of 'std'
    4 |     auto it = std::find(values, values + 3, 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 values[] = {5, 2, 8};
    auto it = std::find(values, values + 3, 2);
    return it == values + 3 ? 1 : 0;
}
Terminal
$ g++ -std=c++20 n_none.cpp -o n_none_prog
n_none.cpp: In function 'int main()':
n_none.cpp:3:20: error: 'find' is not a member of 'std'
    3 |     auto it = std::find(values, values + 3, 2);
      |                    ^~~~

With only <vector>, GCC suggests a different name, std::ranges::find, which that header's own includes do declare:

C++
#include <vector>
int main() {
    int values[] = {5, 2, 8};
    auto it = std::find(values, values + 3, 2);
    return it == values + 3 ? 1 : 0;
}
Terminal
$ g++ -std=c++20 s_vector.cpp -o s_vector_prog
s_vector.cpp: In function 'int main()':
s_vector.cpp:4:20: error: 'find' is not a member of 'std'; did you mean 'std::ranges::find'?
    4 |     auto it = std::find(values, values + 3, 2);
      |                    ^~~~
In file included from /usr/include/c++/13/tuple:44,
                 from /usr/include/c++/13/bits/uses_allocator_args.h:38,
                 from /usr/include/c++/13/bits/memory_resource.h:41,
                 from /usr/include/c++/13/vector:80,
                 from s_vector.cpp:1:
/usr/include/c++/13/bits/ranges_util.h:499:30: note: 'std::ranges::find' declared here
  499 |   inline constexpr __find_fn find{};
      |                              ^~~~

That suggestion is not the fix for a call written as std::find: std::ranges::find is a different name in a nested namespace. The fix for the call as written is the missing include, below.

The textbook version fails too - with a different wording

The version most often written first - search a std::vector, print the result with std::cout - does not compile either, and its error is not the is not a member wording at all:

C++
#include <iostream>
#include <vector>
int main() {
    std::vector<int> values = {5, 2, 8};
    auto it = std::find(values.begin(), values.end(), 2);
    std::cout << (it != values.end() ? *it : -1) << "\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:24: error: no matching function for call to 'find(std::vector<int>::iterator, std::vector<int>::iterator, int)'
    5 |     auto it = std::find(values.begin(), values.end(), 2);
      |               ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/bits/locale_facets.h:48,
                 from /usr/include/c++/13/bits/basic_ios.h:37,
                 from /usr/include/c++/13/ios:46,
                 from /usr/include/c++/13/ostream:40,
                 from /usr/include/c++/13/iostream:41,
                 from t_textbook.cpp:1:
/usr/include/c++/13/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/13/bits/streambuf_iterator.h:435:5: note:   template argument deduction/substitution failed:
t_textbook.cpp:5:24: note:   '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'std::istreambuf_iterator<_CharT>'
    5 |     auto it = std::find(values.begin(), values.end(), 2);
      |               ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

What happened: <iostream> makes one unrelated std::find overload visible - the one for streambuf iterators - so the compiler finds a candidate with that name, rejects it because a std::vector iterator is not a streambuf iterator, and reports no matching function instead of is not a member. Same missing include, different wording. A file whose only include is <iostream>, searching a raw array, gets the same no matching function shape, with the note mismatched types 'std::istreambuf_iterator<_CharT>' and 'int*' under the candidate.

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 searches a raw array with std::find, the outcome splits. These headers fail with the is not a member of 'std' error (the <vector>, <string>, and <mutex> cases add the std::ranges::find suggestion shown above):

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

<iostream> fails too, with the no matching function wording shown above instead. Only one probed header rescues the program - it compiles 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::find, and another library could leave it out. A program that uses std::find includes <algorithm>, whether or not it happens to compile without it.

The same holds for the other failing contexts in the sweep. This program includes only <utility>:

C++
#include <utility>
int main() {
    int values[] = {5, 2, 8};
    auto it = std::find(values, values + 3, 2);
    return it == values + 3 ? 1 : 0;
}
Terminal
$ g++ -std=c++20 a_utility.cpp -o a_utility_prog
a_utility.cpp: In function 'int main()':
a_utility.cpp:4:20: error: 'find' is not a member of 'std'
    4 |     auto it = std::find(values, values + 3, 2);
      |                    ^~~~

And this one includes only <limits>:

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

The fix

Add the header:

C++
#include <algorithm>
#include <iostream>
int main() {
    int values[] = {5, 2, 8};
    auto found = std::find(values, values + 3, 2);
    std::cout << (found != values + 3 ? *found : -1) << "\n";
    auto missing = std::find(values, values + 3, 9);
    std::cout << (missing == values + 3 ? "not found" : "found") << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 h_fixed.cpp -o h_prog
$ ./h_prog
2
not found

One include, <algorithm>, declares the template. Searching {5, 2, 8} for 2 returns an iterator to that element, so the program prints 2; searching for 9 returns the end iterator values + 3, so the second line prints not found. Comparing the returned iterator against the end of the range is how a std::find result is read: equal to the end means absent, anything else points at the match.

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::find_if - the function template that returns an iterator to the first element for which a predicate returns true, or last if there is none - gets its own error, again with no header note:

C++
#include <type_traits>
int main() {
    int values[] = {5, 2, 8};
    auto it = std::find_if(values, values + 3, [](int v) { return v > 6; });
    return it == values + 3 ? 1 : 0;
}
Terminal
$ g++ -std=c++20 b_find_if.cpp -o b_prog
b_find_if.cpp: In function 'int main()':
b_find_if.cpp:4:20: error: 'find_if' is not a member of 'std'
    4 |     auto it = std::find_if(values, values + 3, [](int v) { return v > 6; });
      |                    ^~~~~~~

std::count - the function template that returns the number of elements in a range equal to a given value - fails the same way:

C++
#include <type_traits>
int main() {
    int values[] = {5, 2, 2};
    return static_cast<int>(std::count(values, values + 3, 2));
}
Terminal
$ g++ -std=c++20 c_count.cpp -o c_prog
c_count.cpp: In function 'int main()':
c_count.cpp:4:34: error: 'count' is not a member of 'std'
    4 |     return static_cast<int>(std::count(values, values + 3, 2));
      |                                  ^~~~~

std::count_if, which counts the elements for which a predicate returns true, fails the same way:

C++
#include <type_traits>
int main() {
    int values[] = {5, 2, 8};
    return static_cast<int>(std::count_if(values, values + 3, [](int v) { return v > 4; }));
}
Terminal
$ g++ -std=c++20 d_count_if.cpp -o d_prog
d_count_if.cpp: In function 'int main()':
d_count_if.cpp:4:34: error: 'count_if' is not a member of 'std'
    4 |     return static_cast<int>(std::count_if(values, values + 3, [](int v) { return v > 4; }));
      |                                  ^~~~~~~~

And std::search - the function template that searches for the first occurrence of one range inside another and returns an iterator to its beginning, or last if it does not appear - fails the same way:

C++
#include <type_traits>
int main() {
    int values[] = {5, 2, 8};
    int needle[] = {2, 8};
    auto it = std::search(values, values + 3, needle, needle + 2);
    return it == values + 3 ? 1 : 0;
}
Terminal
$ g++ -std=c++20 e_search.cpp -o e_prog
e_search.cpp: In function 'int main()':
e_search.cpp:5:20: error: 'search' is not a member of 'std'
    5 |     auto it = std::search(values, values + 3, needle, needle + 2);
      |                    ^~~~~~

One added include declares every one of these names: the value search, the predicate search, both counts, and the range search.

The neighboring names, fixed

With <algorithm> added, the container searches and the predicate search all work in short programs. Searching a std::vector for 8 prints 8, and searching a std::string for the character 'd' prints d:

C++
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
int main() {
    std::vector<int> values = {5, 2, 8};
    auto it = std::find(values.begin(), values.end(), 8);
    std::cout << (it != values.end() ? *it : -1) << "\n";
    std::string word = "veldica";
    auto ch = std::find(word.begin(), word.end(), 'd');
    std::cout << (ch != word.end() ? *ch : '?') << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 i_vector_string.cpp -o i_prog
$ ./i_prog
8
d

And std::find_if with a lambda that accepts values greater than 6 finds 8, the first element of {5, 2, 8} that satisfies it, while std::count reports 1 occurrence of the value 2 in the same array:

C++
#include <algorithm>
#include <iostream>
int main() {
    int values[] = {5, 2, 8};
    auto it = std::find_if(values, values + 3, [](int v) { return v > 6; });
    std::cout << (it != values + 3 ? *it : -1) << "\n";
    std::cout << std::count(values, values + 3, 2) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 j_findif.cpp -o j_prog
$ ./j_prog
8
1

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 values[] = {5, 2, 8};
    auto it = find(values, values + 3, 2);
    std::cout << *it << "\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:15: error: 'find' was not declared in this scope
    5 |     auto it = find(values, values + 3, 2);
      |               ^~~~
g_unqualified.cpp:5:15: note: suggested alternatives:
In file included from /usr/include/c++/13/bits/locale_facets.h:48,
                 from /usr/include/c++/13/bits/basic_ios.h:37,
                 from /usr/include/c++/13/ios:46,
                 from /usr/include/c++/13/ostream:40,
                 from /usr/include/c++/13/iostream:41,
                 from g_unqualified.cpp:2:
/usr/include/c++/13/bits/streambuf_iterator.h:435:5: note:   'std::find'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
In file included from /usr/include/c++/13/bits/ranges_algo.h:39,
                 from /usr/include/c++/13/algorithm:63,
                 from g_unqualified.cpp:1:
/usr/include/c++/13/bits/ranges_util.h:499:30: note:   'std::ranges::find'
  499 |   inline constexpr __find_fn find{};
      |                              ^~~~

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::find; adding includes does not bring the name out of namespace std.

The exact rule

  • std::find is declared by #include <algorithm>, and nowhere else by rule. In the sweep probed here, <vector>, <string>, <array>, <type_traits>, <utility>, <numeric>, <limits>, <cmath>, <mutex>, <optional>, and <cstring> do not declare it, and neither does a file with no include at all.
  • 'find' is not a member of 'std' means the <algorithm> include is missing - and, unlike some neighboring errors, GCC prints no note naming <algorithm> under it in the contexts probed here. The suggestion it does print under <vector>, <string>, and <mutex>, std::ranges::find, names another entity, not the header.
  • With <iostream> in the file, the same missing include surfaces as no matching function for call to 'find(...)' instead, because an unrelated std::find overload for streambuf iterators is visible and is the only candidate. The cause and the fix are the same.
  • In the sweep probed here, only <functional> rescues std::find transitively: a file whose only include is <functional> compiles the call without <algorithm>. That is this library version's behavior, not a guarantee - no header is required to pull std::find in.
  • std::find_if, std::count, std::count_if, and std::search 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.
  • 'find' was not declared in this scope for an unqualified find use is a different defect: qualify the name as std::find - 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::find. If <algorithm> is not there, add it - that is the fix in the common case, whether the error reads is not a member of 'std' or no matching function for call.
  • Second, do not follow the suggestion GCC prints under <vector>, <string>, or <mutex> as if it were the fix: std::ranges::find is a different name for a ranges algorithm. It appears because that name is visible in the file, not because it replaces std::find.
  • Third, do not rely on <functional> or any other neighboring header pulling the name in. In the sweep here only that one header does - and no header is required to, so a file that uses std::find includes <algorithm> itself.
  • Fourth, if the error says was not declared in this scope instead, fix the name's qualifier to std::find as well.
  • Fifth, if the failing name is a neighboring one - find_if, count, count_if, or search - 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::find used in a file whose only include is <type_traits>, <utility>, <numeric>, <limits>, <array>, <cmath>, <optional>, or <cstring>, or that includes nothing: the message is 'find' is not a member of 'std', with no header note - add #include <algorithm>.
  • std::find used with only <vector>, <string>, or <mutex> included: the message adds did you mean 'std::ranges::find'? - that is a different name; add #include <algorithm> for the call as written.
  • std::find used with <iostream> in the file (with or without <vector>): the message is no matching function for call to 'find(...)', naming the streambuf-iterator overload as the only candidate - the include is still the missing piece; add #include <algorithm>.
  • Only <functional> included: no error on this library version - add #include <algorithm> anyway, because the rescue is not guaranteed.
  • std::find_if, std::count, std::count_if, or std::search used without <algorithm> in the lean context: the message names that name, with no header note - add #include <algorithm>.
  • find used without the std:: qualifier, <algorithm> included: the message is 'find' was not declared in this scope - qualify the name as std::find.

Checklist

  • Check the include list of the file that names the search, 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 of guessing from the suggestions it does print.
  • Do not be reassured by <vector> or <iostream> being present. In the sweep here neither declares the range std::find - the container header and the output header are not the algorithm header.
  • 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 search - and neither of those headers declares std::find in return.
  • After the fix, confirm the program runs, not just that it compiles: the fixed programs here print 2 and not found for the array search, 8 and d for the vector and string searches, and 8 and 1 for the predicate search and the count.

Sources

  • cppreference, std::find, std::find_if, std::find_if_not — for std::find and std::find_if being function templates defined in <algorithm>: std::find returns an iterator to the first element in [first, last) equal to the given value using operator==, or last if there is none, and std::find_if returns an iterator to the first element for which the predicate returns true, or last if there is none.
  • cppreference, Standard library header <algorithm> — for <algorithm> being the header that declares the std::find, std::find_if, std::count, std::count_if, and std::search function templates.
  • cppreference, std::count, std::count_if — for std::count and std::count_if being function templates defined in <algorithm> that return the number of elements in a range equal to a given value, or for which a predicate returns true, respectively.
  • cppreference, std::search — for std::search being a function template defined in <algorithm> that searches for the first occurrence of a target range inside a source range and returns an iterator to its beginning, or the end of the source range if the target does not appear.

Keep Exploring