zoukankan      html  css  js  c++  java
  • vector-begin

    ////////////////////////////////////////
    //      2018/04/15 19:00:54
    //      vector-begin
    
    #include <iostream>
    #include <vector>
    #include <iterator>
    #include <numeric>
    
    using namespace std;
    
    int main(){
        vector<int> v(5);
    
        // iota函数:STL序列依次递增函数
        iota(v.begin(), v.end(), 1);
        /*
        iota 源码
        void iota(_FwdIt _First, _FwdIt _Last, _Ty _Val)
        {   // compute increasing sequence into [_First, _Last)
        _DEBUG_RANGE(_First, _Last);
        _Iota(_Unchecked(_First), _Unchecked(_Last), _Val);
        }
        void _Iota(_FwdIt _First, _FwdIt _Last, _Ty _Val)
        {
        // compute increasing sequence into [_First, _Last)
        for (; _First != _Last; ++_First, ++_Val)
        *_First = _Val;
        }
        */
    
        vector<int>::iterator it = v.begin();
        while (it != v.end()){
            cout << *(it++) << " ";
        }
        cout << endl;
    
        // third element of the vector
        it = v.begin() + 2;
        cout << *it << endl;
        return 0;
    }
    
    
    /*
    OUTPUT:
        1 2 3 4 5
        3
    */ 
  • 相关阅读:
    DML数据操作语言练习
    表的操作练习
    20151218--地区导航习题
    20151217--Ajax的一点补充
    02151216--Ajax
    json(转)
    Node.js(转) -- 临时来说还看不懂!
    20151113--JSTL
    20151210--MVC
    链表(转)
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12538055.html
Copyright © 2011-2022 走看看