算数生成算法属于小型算法,使用时包含头文件
accmulate(iterator beg,iterator end,value):计算容器元素累计总和
beg:开始迭代器
end:结束迭代器
value:起始值
#include#include #include using namespace std; void test1() { vector v1; for (int i = 0; i <= 100; i++) { v1.push_back(i); } accumulate(v1.begin(), v1.end(), 0);//0是起始值,从这里开始累加 }
fill(iterator beg,iterator end,value):向容器中添加元素
beg 开始迭代器
end 结束迭代器
value 填充值
#include#include #include #include using namespace std; void myprint(int val) { cout << val << " "; } void test1() { vector v; v.resize(10); //后期重新填充 fill(v.begin(), v.end(), 100); for_each(v.begin(), v.end(), myprint); cout << endl; }



