【C++<numeric>】iota函数:递增序列填充

函数原型

1 template<typename _ForwardIterator, typename _Tp>
2     void
3     iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value)

函数功能

  以_Tp__value为初始值,递增填充前向迭代器范围内的元素,这就要求_Tp类型必须支持++操作符

 1 #include <vector>
 2 #include <iostream>
 3 #include <numeric>  //for iota()
 4 #include <algorithm>  //for copy()
 5 #include <iterator>  //for ostream_iterator<T>
 6 
 7 using namespace std;
 8 
 9 int main()
10 {
11     vector<int> ivec(10);
12     iota(ivec.begin(), ivec.end(), 0);
13     copy(ivec.begin(), ivec.end(), ostream_iterator<int>(cout, " "));
14     cout << endl; 
15     //输出 0 1 2 3 4 5 6 7 8 9 
16     return 0;
17 }

 

猜你喜欢

转载自www.cnblogs.com/chen-cs/p/12903935.html
今日推荐