标准模板库

来源:互联网 发布:u盘格式化数据恢复软件 编辑:程序博客网 时间:2024/06/07 07:00
#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");}
0 0
原创粉丝点击