#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<numeric>
#include<list>
using namespace std;
//STL算法 accumulate
//对顺序表元素进行累加求和
template<class T>
T sum(T *a, int n)
{
//int thesum=0;
int theProduct = 1;//初始化
//return accumulate(a, a + n, thesum);//求和
return accumulate(a, a + n, theProduct, multiplies<T>());//求积
}
//copy函数的使用 copy(start,end,to)
//template<class T>
void main()
{
int thesum = 0;
int a[2] = { 14, 3 };
cout <<sum<int>(a,2)<< endl;
list<int> list1;
list<int> list2;
list2.push_back(1);
list2.push_back(2);
//cout << copy(list2, 2, list1) << endl;
system("pause");
}
标准模板库
最新推荐文章于 2018-05-30 19:48:52 发布