当前位置: 代码迷 >> 综合 >> vector-begin
  详细解决方案

vector-begin

热度:61   发布时间:2023-12-15 04:30:55.0

// 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 vectorit = v.begin() + 2;cout << *it << endl;return 0;
}/* OUTPUT:1 2 3 4 53 */ 
  相关解决方案