功能描述:
- 计算区间内容器元素累记总和
函数原型:
- accumulate(iterator beg, iterator end, value);
//计算容器元素累加总和
//beg开始迭代器
//end结束迭代器
//value起始值
代码演示:
#include<iostream>#include<numeric>#include<vector>using namespace std;//常用算数生成算法 accumlatevoid test01() {vector<int>v;for (int i = 1; i <= 100; i++) {v.push_back(i);}//参数3是起始累加值int total = accumulate(v.begin(), v.end(), 0);cout << "total = " << total << endl;}int main() {test01();return 0;}
运行结果:
注意:
accumulate函数的头文件为#include
