C++ iota() 递增赋值

定义于头文件<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

发布了73 篇原创文章 · 获赞 26 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/l503301397/article/details/103692723