常用的算术生成算法
#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
#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;
}
本文作者: 永生
本文链接: https://yys.zone/detail/?id=103
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!
发表评论
评论列表 (0 条评论)
暂无评论,快来抢沙发吧!