zoukankan      html  css  js  c++  java
  • 【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 }

     

  • 相关阅读:
    foreach
    if
    注意事项
    Maven测试
    课程评价
    个人总结
    HTML表格CSS美化
    让多个输入框对齐
    CSS样式写在JSP代码中的几种方法
    日常
  • 原文地址:https://www.cnblogs.com/chen-cs/p/12903935.html
Copyright © 2011-2022 走看看