[C++STL]常用算术生成算法
生活随笔
收集整理的這篇文章主要介紹了
[C++STL]常用算术生成算法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
代碼如下:
#include <iostream> #include <vector> #include <numeric> using namespace std;void test01() {vector<int>v;for (int i = 0; i < 10; i++){v.push_back(i);}int total = accumulate(v.begin(), v.end(), 0);cout << "total = " << total << endl; }int main() {test01();return 0; }測試結果:
總結:
代碼如下:
#include <iostream> #include <vector> #include <numeric> #include <algorithm> using namespace std;class myPrint { public:void operator()(int val){cout << val << " ";} };void test01() {vector<int>v;v.resize(10);fill(v.begin(), v.end(), 100);for_each(v.begin(), v.end(), myPrint());cout << endl; }int main() {test01();return 0; }測試結果:
總結:
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的[C++STL]常用算术生成算法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 七牛云存储怎么建站(七牛云储存怎么用)
- 下一篇: 微信怎么开通公众号(微信开通公众号的方法