0.前言
1.accumulate
#include <iostream>
using namespace std;
// 常用算术生成算法
#include<vector>
#include<numeric> //accumulate 的调用头文件
void test01()
{
vector<int>v;
for (int i = 0; i <= 100; i++)
{
v.push_back(i);
}
int total = accumulate(v.begin(), v.end(), 10000); //10000 是初始值
cout << "Total = " << total << endl;
}
int main()
{
test01();
cout << "------------------------" << endl;
//test02();
//cout << "------------------------" << endl << endl;
//test03();
//**************************************
system("pause");
return 0;
}
2.fill
#include <iostream>
using namespace std;
// 常用算术生成算法 fill
#include<vector>
#include<numeric> //fill 的头文件
#include<algorithm> //for_each 的头文件
void myPrint(int val)
{
cout << val << " ";
}
void test01()
{
vector<int>v;
v.resize(10);
cout << "填充前:" << endl;
for_each(v.begin(), v.end(), myPrint);
cout << endl;
fill(v.begin(), v.end(), 100);
cout << "填充后:" << endl;
for_each(v.begin(), v.end(), myPrint);
cout << endl;
}
int main()
{
test01();
cout << "------------------------" << endl;
//test02();
//cout << "------------------------" << endl << endl;
//test03();
//**************************************
system("pause");
return 0;
}