C++
'std::iota' Is Not a Member of 'std' Fix
std::iota lives in one header, <numeric> - not <algorithm>, where its fill-and-sort neighbors live - and in the sweep probed here no other header pulls it in on the side, so this error does not hide: the textbook file that fills a vector and prints it gets it in full, exactly like the 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 · 11 min read
- The error: the include is missing
- The textbook version fails too - neither textbook header rescues it
- Neighboring headers: none of the probed ones rescue it
- The fix
Written November 30, 2026
Tested with GCC 13.3.0
What this guide is
std::iota is a function template defined in the header <numeric>. It fills the range [first, last) with sequentially increasing values, starting with the given value and repeatedly applying ++value to it.
Because the template lives in one specific header, 'iota' is not a member of 'std' has one common cause:
- The
#include <numeric>line is missing. For this error GCC prints no note naming<numeric>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.
Two traps surround this name. The first is the header guess: std::iota fills a range, so it looks like a sibling of std::fill and std::sort - but those live in <algorithm>, and <algorithm> does not declare std::iota; a file whose only include is <algorithm> gets this same error. The second trap is the opposite of the usual one: for many names a missing include stays hidden because a common header pulls the name in transitively, but in the sweep probed here no header rescues std::iota at all - not <vector>, not <string>, not <iostream>. The textbook version fails alongside the lean one. Each case is separated below.
The error: the include is missing
This program fills the array {0, 0, 0} with increasing values starting at 10 using std::iota, but includes only <type_traits>:
#include <type_traits>
int main() {
int a[] = {0, 0, 0};
std::iota(a, a + 3, 10);
return a[0] == 10 && a[2] == 12 ? 0 : 1;
}
$ 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: 'iota' is not a member of 'std'
4 | std::iota(a, a + 3, 10);
| ^~~~
That is the whole output: one error, no note, no suggestion. The same program with no include at all fails the same way:
int main() {
int a[] = {0, 0, 0};
std::iota(a, a + 3, 10);
return a[0] == 10 && a[2] == 12 ? 0 : 1;
}
$ g++ -std=c++20 n_none.cpp -o n_none_prog
n_none.cpp: In function 'int main()':
n_none.cpp:3:10: error: 'iota' is not a member of 'std'
3 | std::iota(a, a + 3, 10);
| ^~~~
The textbook version fails too - neither textbook header rescues it
The version most often written first - fill a vector with increasing values and print the elements with std::cout - fails without <numeric>:
#include <iostream>
#include <vector>
int main() {
std::vector<int> v(3);
std::iota(v.begin(), v.end(), 10);
for (int x : v) std::cout << x << " ";
std::cout << "\n";
return 0;
}
$ g++ -std=c++20 t_textbook.cpp -o t_textbook_prog
t_textbook.cpp: In function 'int main()':
t_textbook.cpp:5:10: error: 'iota' is not a member of 'std'
5 | std::iota(v.begin(), v.end(), 10);
| ^~~~
That is the same error the lean file gets. Neither <vector> nor <iostream> pulls the name in on this library version, alone or together, so neither of those common headers hides the error - in the sweep probed here, the missing <numeric> shows itself in the first file that uses the name. No header except <numeric> is required to declare std::iota, and a program that uses std::iota includes <numeric> rather than hoping for a rescue that, in the sweep probed here, never comes.
Neighboring headers: none of the probed ones rescue it
In a sweep where each header below was compiled as the only header in a program that fills the array {0, 0, 0} with increasing values starting at 10, every probed header fails with the plain is not a member of 'std' error, with no note and no suggestion:
<type_traits><utility><algorithm><limits><mutex><optional><cstring><vector><string><iostream><functional><array><memory>
A file with no include at all fails the same way. Only <numeric> itself compiles the program - it is the one header in the sweep that declares the name.
Those outcomes are properties of this library version, not rules of the language - no header except <numeric> is required to declare std::iota, and another library could pull it into one of these headers. What the sweep rules out is relying on it here.
This program includes only <utility>:
#include <utility>
int main() {
int a[] = {0, 0, 0};
std::iota(a, a + 3, 10);
return a[0] == 10 && a[2] == 12 ? 0 : 1;
}
$ g++ -std=c++20 s_utility.cpp -o s_utility_prog
s_utility.cpp: In function 'int main()':
s_utility.cpp:4:10: error: 'iota' is not a member of 'std'
4 | std::iota(a, a + 3, 10);
| ^~~~
And this one includes only <algorithm> - the header that declares the fill, search, and sort algorithms this name is so often grouped with, which still does not declare this one:
#include <algorithm>
int main() {
int a[] = {0, 0, 0};
std::iota(a, a + 3, 10);
return a[0] == 10 && a[2] == 12 ? 0 : 1;
}
$ g++ -std=c++20 s_algorithm.cpp -o s_algorithm_prog
s_algorithm.cpp: In function 'int main()':
s_algorithm.cpp:4:10: error: 'iota' is not a member of 'std'
4 | std::iota(a, a + 3, 10);
| ^~~~
The fix
Add the header:
#include <iostream>
#include <numeric>
int main() {
int a[] = {0, 0, 0};
std::iota(a, a + 3, 10);
for (int x : a) std::cout << x << " ";
std::cout << "\n";
return 0;
}
$ g++ -std=c++20 h_fixed.cpp -o h_prog
$ ./h_prog
10 11 12
One include, <numeric>, declares the template. std::iota(a, a + 3, 10) writes 10 to the first element and ++value - 11, then 12 - to each next one, so the program prints 10 11 12.
The neighboring names: the whole header family fails too
The other names declared by <numeric> fail with the same shape of error in the same lean context. std::reduce - the function template in the same header that reduces a range to a single value - gets its own error, again with no header note and no suggestion:
#include <type_traits>
int main() {
int a[] = {1, 2, 3};
auto s = std::reduce(a, a + 3);
return s == 6 ? 0 : 1;
}
$ g++ -std=c++20 b_reduce.cpp -o b_prog
b_reduce.cpp: In function 'int main()':
b_reduce.cpp:4:19: error: 'reduce' is not a member of 'std'
4 | auto s = std::reduce(a, a + 3);
| ^~~~~~
And std::inner_product, the function template in the same header that sums the pairwise products of two ranges, fails the same way:
#include <type_traits>
int main() {
int a[] = {1, 2, 3};
int b[] = {4, 5, 6};
auto s = std::inner_product(a, a + 3, b, 0);
return s == 32 ? 0 : 1;
}
$ g++ -std=c++20 c_inner_product.cpp -o c_prog
c_inner_product.cpp: In function 'int main()':
c_inner_product.cpp:5:19: error: 'inner_product' is not a member of 'std'
5 | auto s = std::inner_product(a, a + 3, b, 0);
| ^~~~~~~~~~~~~
std::accumulate, the summing function in the same header, fails with this same shape of error when <numeric> is missing - it has its own guide, linked below, so it is not re-derived here. One added include declares every one of these names: the sequence fill, the reduce, the inner product, and the sum.
The neighboring names, fixed
With <numeric> added, std::iota works on more than a plain array of int. The vector of four elements prints as 5 6 7 8 after the fill starting at 5, and the character array becomes abcd - std::iota applies ++ to the starting value 'a', so each next element holds the next character:
#include <iostream>
#include <numeric>
#include <vector>
int main() {
std::vector<int> v(4);
std::iota(v.begin(), v.end(), 5);
for (int x : v) std::cout << x << " ";
std::cout << "\n";
char c[] = {0, 0, 0, 0};
std::iota(c, c + 4, 'a');
for (char ch : c) std::cout << ch;
std::cout << "\n";
return 0;
}
$ g++ -std=c++20 i_vector_chars.cpp -o i_prog
$ ./i_prog
5 6 7 8
abcd
The starting value only needs a working ++: this type's operator++ steps its member by ten, so filling three elements starting from Step{1} prints 1 11 21:
#include <iostream>
#include <numeric>
struct Step {
int v;
Step& operator++() { v += 10; return *this; }
};
int main() {
Step s[3] = {{1}, {0}, {0}};
std::iota(s, s + 3, Step{1});
for (const Step& x : s) std::cout << x.v << " ";
std::cout << "\n";
return 0;
}
$ g++ -std=c++20 j_custom.cpp -o j_prog
$ ./j_prog
1 11 21
And the neighboring names run under the same added include: std::reduce over {1, 2, 3} prints 6, and std::inner_product of {1, 2, 3} with {4, 5, 6} starting from 0 prints 32:
#include <iostream>
#include <numeric>
int main() {
int a[] = {1, 2, 3};
int b[] = {4, 5, 6};
std::cout << std::reduce(a, a + 3) << " " << std::inner_product(a, a + 3, b, 0) << "\n";
return 0;
}
$ g++ -std=c++20 k_neighbors_fixed.cpp -o k_prog
$ ./k_prog
6 32
A different wording: the name without its qualifier
Including <numeric> is not the only half of the name. This program includes the header but drops the std:: qualifier:
#include <iostream>
#include <numeric>
int main() {
int a[] = {0, 0, 0};
iota(a, a + 3, 10);
for (int x : a) std::cout << x << " ";
std::cout << "\n";
return 0;
}
$ g++ -std=c++20 g_unqualified.cpp -o g_prog
g_unqualified.cpp: In function 'int main()':
g_unqualified.cpp:5:5: error: 'iota' was not declared in this scope; did you mean 'std::iota'?
5 | iota(a, a + 3, 10);
| ^~~~
| std::iota
In file included from /usr/include/c++/13/numeric:62,
from g_unqualified.cpp:2:
/usr/include/c++/13/bits/stl_numeric.h:88:5: note: 'std::iota' declared here
88 | iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value)
| ^~~~
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::iota; adding includes does not bring the name out of namespace std. Here the suggestion names the right function outright - did you mean 'std::iota'?, with the note pointing at the declaration the <numeric> include brought in - so this wording, unlike the missing-include error above, tells the reader exactly what to change.
The exact rule
std::iotais declared by#include <numeric>, and nowhere else by rule. In the sweep probed here,<type_traits>,<utility>,<algorithm>,<limits>,<mutex>,<optional>,<cstring>,<vector>,<string>,<iostream>,<functional>,<array>, and<memory>do not declare it, and neither does a file with no include at all.'iota' is not a member of 'std'means the<numeric>include is missing - and, in the contexts probed here, GCC prints no note naming<numeric>and no suggestion under it.- In the sweep probed here, no probed header rescues
std::iotatransitively: a file whose only include is any one of the thirteen headers above fails the call, and the textbook file with<vector>and<iostream>together fails it too. That is this library version's behavior, not a guarantee - no header is required to leavestd::iotaout, either. std::iotais not declared by<algorithm>: the fill-and-sort header that declares its look-alike neighborsstd::fillandstd::sortleaves this name out, in the program shown here and in the sweep.std::reduceandstd::inner_productare declared by the same#include <numeric>: in the programs shown here, which include only<type_traits>beside the use, each gets its ownis not a member of 'std'error when that include is missing, with no header note and no suggestion.'iota' was not declared in this scopefor an unqualifiediotause is a different defect: qualify the name asstd::iota- the include alone does not bring the name out of namespacestd.
The fixes, ranked
- First, check the include list of the file that names
std::iota. If<numeric>is not there, add it - that is the fix in the common case. - Second, do not substitute
<algorithm>for it.std::iotafills a range, but it is a numeric algorithm, not an<algorithm>one - in the sweep here the<algorithm>-only file fails with the same error. - 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,
<numeric>. - Fourth, if the error says
was not declared in this scopeinstead, fix the name's qualifier tostd::iotaas well - there GCC does suggest the qualified name. - Fifth, if the failing name is a neighboring one -
reduce,inner_product, oraccumulate- 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 <numeric>missing,std::iotaused in a file whose only include is any of<type_traits>,<utility>,<algorithm>,<limits>,<mutex>,<optional>,<cstring>,<vector>,<string>,<iostream>,<functional>,<array>, or<memory>, or that includes nothing: the message is'iota' is not a member of 'std', with no header note and no suggestion - add#include <numeric>.std::iotaused in a textbook file with<vector>and<iostream>included: the same message - neither header rescues the name on this library version, so add#include <numeric>there too.std::reduceorstd::inner_productused without<numeric>in the lean context: the message names that name, with no header note - add#include <numeric>.iotaused without thestd::qualifier,<numeric>included: the message is'iota' was not declared in this scope, with a suggestion namingstd::iota- qualify the name asstd::iota.
Checklist
- Check the include list of the file that names the fill, 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,
<numeric>, instead. - Do not guess
<algorithm>from the name's job.std::iotafills a range likestd::filldoes, but the two names live in different headers -<numeric>foriota,<algorithm>forfill. - Do not be reassured or alarmed by the file's size: in the sweep here the textbook file fails exactly like the lean one, because no probed header rescues this name - the include belongs in every file that uses it.
- One header per name the file uses:
std::vectorcomes from<vector>andstd::coutfrom<iostream>, even in a program whose subject is the fill - andstd::iotacomes from<numeric>in return. - After the fix, confirm the program runs, not just that it compiles: the fixed programs here print
10 11 12for the filled array,5 6 7 8andabcdfor the vector and the character array,1 11 21for the custom stepped type, and6 32for the reduced sum and the inner product.
Related guides
- 'std::accumulate' Is Not a Member of 'std' Fix - the same missing-include shape for the summing function in the same header,
<numeric>; the one include added there is the one added here. - 'std::fill' Is Not a Member of 'std' Fix - the contrasting case:
std::fillfills a range with one repeated value wherestd::iotafills it with increasing ones,std::filllives in<algorithm>wherestd::iotadoes not, and many common headers rescuestd::fillwhere none of the probed headers rescuestd::iota.
Sources
- cppreference,
std::iota— forstd::iotabeing a function template defined in<numeric>that fills the range[first, last)with sequentially increasing values, starting with the given value and repeatedly evaluating++value, with exactlylast - firstincrements and assignments. - cppreference, Standard library header
<numeric>— for<numeric>being the header that declares thestd::iota,std::accumulate,std::inner_product, andstd::reducefunction templates. - cppreference,
std::reduce— forstd::reducebeing a function template defined in<numeric>that reduces a range to a single value. - cppreference,
std::inner_product— forstd::inner_productbeing a function template defined in<numeric>that computes the sum of the pairwise products of two ranges, accumulated onto an initial value.
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.