使用类属性算法accumulate和multiplies计算连乘积示例如下:
#include#include #include #include #include
using namespace std;int main(){ int a[10]={12,3,25,7,11,213,7,123,29,-31}; //int *ptr=find(&a[0],&a[10],7); //assert (*ptr==7 && *(ptr+1)==11); list list1(&a[0],&a[10]); list ::iterator i=find(list1.begin(),list1.end(),7); assert (*i==7 && *(++i)==11); cout<<"Type some characters,including an 'x' followed\n"<<"by at least one nonwhite-space character: "< in(cin); istream_iterator eos; find(in,eos,'x'); cout<<"The first nonwhite-space character following\n"<<"the first 'x' was '"<<*(++in)<<"'."< #include #include #include #include using namespace std;int main(){ cout<<"Using generic accumulate algorithm to compute a product."<