定义于头文件<numeric>
和<algorithm>
C++11开始到C++20前:
template< class ForeardIt, class T >
void iota( ForwardIt first, ForwardIt last, T value );
C++20开始:
template< class ForeardIt, class T >
constexpr void iota( ForwardIt first, ForwardIt last, T value );
以始于value并重复地求值++value
的顺序递增值填充范围[first, last)。
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void o(int a)
{
cout<<a<<" ";
}
int main()
{
vector<int>v(10);
iota(v.begin(),v.end(),0);
for_each(v.begin(),v.end(),o);
return 0;
}
运行结果:
0 1 2 3 4 5 6 7 8 9