C++ 常用算数生成算法
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                C++ 常用算数生成算法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                
                            
                            
                            #define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include <vector>
using namespace std;
#include <algorithm> //不好使
#include <numeric> //好使
#include <iterator>
/*
accumulate算法 計算容器元素累計總和
@param beg 容器開始迭代器
@param end 容器結束迭代器
@param value累加值
*/
void test01()
{vector<int>v;for (int i = 0; i <= 100;i++){v.push_back(i);}//0~100累積和  5050//第三個參數  起始累加值int sum = accumulate(v.begin(), v.end(), 0);cout << "總和為:" << sum << endl;}/*
fill算法 向容器中添加元素
@param beg 容器開始迭代器
@param end 容器結束迭代器
@param value t填充元素
*/void test02()
{vector<int>v;v.resize(10);fill(v.begin(), v.end(), 1000);copy(v.begin(), v.end(), ostream_iterator<int>(cout, " "));}int main(){//test01();test02();system("pause");return EXIT_SUCCESS;
}
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎
                            
                        
                        
                        總結
以上是生活随笔為你收集整理的C++ 常用算数生成算法的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: antd react date-pick
- 下一篇: C++ 常用集合算法
