C++常用算术生成算法-accumulate()
功能描述:
- 计算区间内 容器元素累计总和
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
void test01()
{
vector<int> v;
for (int i = 0; i <= 100; i++)
{
v.push_back(i);
}
int total = accumulate(v.begin(), v.end(), 0);
cout << "total = " << total << endl;
}
int main()
{
test01();
return 0;
}
//accumulate使用时头文件注意numeric这种算法很实用
C++常用算术生成算法-accumulate()