c++STL之常用算术生成算法

c++STL之常用算术生成算法,第1张

概述accumulate:计算容器元素累计总和 fill:向容器中添加元素 1.accumulate #include<iostream> using namespace std; #incl

accumulate:计算容器元素累计总和

fill:向容器中添加元素

1.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);    }    参数3  起始累加值    int total = accumulate(v.begin(),v.end(),0);    cout << "total = " << total << endl;}int main() {    test01();    system(pause");    return ;}

2.fill

#include<iostream>#include <numeric>#include <algorithm>常用算术生成算法 fillvoID myPrint( val){    cout << val << " ;}v;    v.resize(10后期重新填充    fill(v.begin(),1)">100);    for_each(v.begin(),myPrint);    cout <<;}
总结

以上是内存溢出为你收集整理的 c++STL之常用算术生成算法全部内容,希望文章能够帮你解决 c++STL之常用算术生成算法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1159644.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)

保存