01 常用的算术生成算法_accumulate
02 常用的算术生成算法_fill
01 常用的算术生成算法_accumulate
#include<iostream>
using namespace std;
#include<vector>
#include<numeric>
void test01()
{
vector<int> v;
for (int i = 0; i <= 100; i++)
{
v.push_back(i);
}
int count = accumulate(v.begin(), v.end(), 0); //参数3起始累加值
cout << "累加得" << count <<endl;
}
int main()
{
test01();
system("pause");
return 0;
}
//总结,注意算法头文件numeric
02 常用的算术生成算法_fill
#include<iostream>
using namespace std;
#include<vector>
#include<numeric>
#include<algorithm>
void print(int val)
{
cout << val << " ";
}
void test01()
{
vector<int> v;
v.resize(10);
//后期重新填充
fill(v.begin(), v.end(), 100);
for_each(v.begin(), v.end(), print);
cout << endl;
}
int main()
{
test01();
system("pause");
return 0;
}
评论区(0 条)
发表评论⏳ 加载编辑器…