C++
'std::accumulate' Is Not a Member of 'std' Fix
The summing function that looks like an algorithm does not live in the algorithm header. It lives in
Written November 28, 2026 · Tested with GCC 13.3.0 · 5 min read
- The rule underneath
- The first failure: the algorithm header alone
- The header sweep: three headers that do not help
- The fix
Written November 28, 2026
Tested with GCC 13.3.0
What this guide is
std::accumulate is a function template defined in the header <numeric>. It computes the sum of an initial value and every element in a range, working from left to right: it starts with the initial value, adds the first element, then the next, and returns the total. A second form takes a custom operation in place of addition.
The trap is the name's company. Most range functions a program calls day to day - sorting, searching, copying - live in <algorithm>, so <algorithm> is the header a hand reaches for here too. This function is not one of them. A file that includes <algorithm> and calls the function anyway gets one error, and, unlike many missing-include errors, this one comes with no note naming the header that would fix it:
- The
#include <numeric>line is missing. The fix is that include, and nothing in the error message points at it.
The rule underneath
The header page for <numeric> lists the numeric operations as one group: the summing function, its parallel relative, inner product, partial sums, scans, and a few arithmetic helpers. They were grouped by what they compute - numbers out of ranges - rather than by the range-walking shape they share with the algorithms. So the split a program has to learn is by header, not by feel:
- Range operations that reorder, search, or copy live in
<algorithm>. - Range operations that reduce a range to a number live in
<numeric>.
One more rule sits inside the call itself, and a later section shows it costing a digit. The type of the result is the type of the initial value. The accumulator starts as that type and stays that type, so an initial value of 0 makes an integer accumulator even when every element in the range is a fractional number.
The first failure: the algorithm header alone
This program sums three integers and includes the headers for the container, the output stream, and the algorithms - everything except the one header that declares the function:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v{1, 2, 3};
std::cout << std::accumulate(v.begin(), v.end(), 0) << "\n";
return 0;
}
$ g++ -std=c++20 a_noinclude.cpp -o a_prog
a_noinclude.cpp: In function 'int main()':
a_noinclude.cpp:6:23: error: 'accumulate' is not a member of 'std'
6 | std::cout << std::accumulate(v.begin(), v.end(), 0) << "\n";
| ^~~~~~~~~~
That is the whole diagnostic. There is one error, the caret sits under the function name, and there is no note after it - no line saying the name is defined in some header, and no suggested include to add. Compare the shape with the missing-include errors that do carry such a note: here a reader who trusts the compiler to name the header waits for help that never comes. The name is simply absent, because no included header declared it, and the header that declares it is not the one the call resembles.
The header sweep: three headers that do not help
Adding a plausible neighbor does not change the outcome. Added one at a time to the failing program, on top of <algorithm>, <iostream>, and <vector>, these headers each fail with the same error, 'accumulate' is not a member of 'std':
<ranges><functional><iterator>
Each is a reasonable guess. Ranges work walks ranges, the functional header supplies the operation objects a custom summing call can use, and the iterator header is where the begin and end iterators come from. None of them declares this function, not even by accident. Only one header in the sweep declares it:
<numeric>- the program compiles and prints6.
There is no accidental rescue to rely on here either. A program that sums a range includes <numeric>.
The fix
Add the header:
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
int main() {
std::vector<int> v{1, 2, 3};
std::cout << std::accumulate(v.begin(), v.end(), 0) << "\n";
return 0;
}
$ g++ -std=c++20 a_fixed.cpp -o a_fixed_prog
$ ./a_fixed_prog
6
One include declares the function. The accumulator starts at 0, adds 1, 2, and 3 in order, and the program prints the total, 6. The <algorithm> include can stay or go - this program uses nothing from it - but <numeric> is the line that does the work.
The initial value sets the type
The same call has a second trap that survives the include fix, because it compiles and runs and quietly returns a wrong total. Summing fractional values with an integer initial value truncates at every step:
#include <iostream>
#include <numeric>
#include <vector>
int main() {
std::vector<double> v{1.5, 2.5, 3.0};
std::cout << std::accumulate(v.begin(), v.end(), 0) << "\n";
return 0;
}
$ g++ -std=c++20 b_int_init.cpp -o b_prog
$ ./b_prog
6
The true sum is 7. The accumulator is an int, because the initial value 0 is an int, so each addition converts back to int before the next one: 0 plus 1.5 becomes 1, plus 2.5 becomes 3, plus 3.0 becomes 6. The fractions are not rounded at the end; they are cut away one step at a time. Give the accumulator the element type by writing the initial value as a fractional literal:
#include <iostream>
#include <numeric>
#include <vector>
int main() {
std::vector<double> v{1.5, 2.5, 3.0};
std::cout << std::accumulate(v.begin(), v.end(), 0.0) << "\n";
return 0;
}
$ g++ -std=c++20 b_double_init.cpp -o b_double_prog
$ ./b_double_prog
7
Now the accumulator is a double, nothing is truncated, and the program prints 7. The rule travels with the call: match the initial value's type to the total the program actually wants, not to the neatest literal.
Neighboring error: the parallel relative fails the same way
std::reduce is the neighboring function in the same header - similar to the summing function, except out of order, which is what lets it run in parallel. It has the same address, so it has the same failure. Under <algorithm> alone:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v{1, 2, 3};
std::cout << std::reduce(v.begin(), v.end(), 0) << "\n";
return 0;
}
$ g++ -std=c++20 c_reduce_noinclude.cpp -o c_prog
c_reduce_noinclude.cpp: In function 'int main()':
c_reduce_noinclude.cpp:6:23: error: 'reduce' is not a member of 'std'
6 | std::cout << std::reduce(v.begin(), v.end(), 0) << "\n";
| ^~~~~~
Same shape, one name over: 'reduce' is not a member of 'std', no header note, and the same fix. With <numeric> added, the program compiles and prints the same total:
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
int main() {
std::vector<int> v{1, 2, 3};
std::cout << std::reduce(v.begin(), v.end(), 0) << "\n";
return 0;
}
$ g++ -std=c++20 c_reduce_fixed.cpp -o c_fixed_prog
$ ./c_fixed_prog
6
Seeing either error in a file is a cue to check the other name too: a file that sums ranges in both ways needs the one include for both, and the include fixes both at once.
Decision summary
- The error is
'accumulate' is not a member of 'std'and no note follows it: the file is missing<numeric>- add it; do not wait for a header hint, because this error prints none. - The file includes
<algorithm>and the call still fails: that is expected - the function does not live in<algorithm>, however much the call looks like an algorithm. - Adding
<ranges>,<functional>, or<iterator>changed nothing: none of those headers declares the function - add<numeric>instead. - The error names
reduceinstead: the same defect in the same header - add<numeric>, which declares both functions. - The program compiles but a sum of fractional values comes out low and whole: the initial value is an integer literal - write it in the element type, such as
0.0for a range ofdoublevalues.
Checklist
- The file that calls the function includes
<numeric>itself, not through a neighbor -<algorithm>,<ranges>,<functional>, and<iterator>do not declare it. - No header note under the error is normal for this name; its absence does not mean the cause is something other than a missing include.
- The initial value's type matches the type of total wanted: an integer initial value makes an integer accumulator, whatever the elements are.
- After the fix, the program runs, not just compiles: the fixed program here prints
6. - A file using both the summing function and its parallel relative needs the one
<numeric>include for both.
Related guides
- 'std::sort' Is Not a Member of 'std' Fix - the closest sibling in the other direction: a function that really does live in
<algorithm>, failing when that header is the one missing. - 'std::vector' Is Not a Member of 'std' Fix - the same missing-include shape for the container the programs here sum over.
- Build a C++ Ranges Pipeline: C++20 Views, Then C++23, With the Compiler Matrix - range work in the views style, for after the include is fixed and the range itself is the subject.
Sources
- cppreference,
std::accumulate- for the function being defined in header<numeric>, for it computing the sum of the initial value and all elements in the range as a left fold that starts from the initial value and adds each element in order, and for the warning that, left to type inference, the operation works in the type of the initial value, so summing a range ofdoublevalues starting from0likely does not give the result wished for. - cppreference, Standard library header
<numeric>- for the header's synopsis listing both the summing function andstd::reduceamong the declarations<numeric>provides, which is the shared address behind both errors in this guide.
Keep Exploring
Seven tips and seven puzzles so far, each one a short runnable example with the fix explained.
Paste an AddressSanitizer, UBSan, or ThreadSanitizer report and get the bug, the file and line, and the fix \u2014 in plain language.
C++20 and C++23 features, migration paths, and measured trade-offs.
The full C++ hub \u2014 language basics, the standard library, coroutines, and measured comparisons.
Paste a [Service] section and get a plain-language verdict on every sandboxing setting it finds.