17.常用算术生成算法-accumulate

2021-05-16  本文已影响0人  lxr_
#include<iostream>
using namespace std;

#include<vector>
#include<algorithm>
#include<functional>
#include<numeric>

//accumulate计算容器元素累加和
//fill      向容器中添加元素

void test1701()
{
    vector<int> v;

    for (int i = 0; i <= 100; i++)
    {
        v.push_back(i);
    }

    //参数3为起始累加值,即最终结果为  100+容器的累加和
    int total=accumulate(v.begin(), v.end(), 1000);
    cout << "total=" << total << endl;
}

int main()
{
    test1701();

    system("pause");
    return 0;
}
上一篇 下一篇

猜你喜欢

热点阅读