//將一組輸入的整數求和ios
#include<iostream>
#include<iterator>
#include<numeric>
using namespace std;函數
int main(int argc,char *argv[])
{
istream_iterator<int> in(cin),eof;
cout<<accumulate(in,eof,0)<<endl;//調用accumulate函數spa
return 0;orm
}ci
//用lambda表達式輸出絕對值it
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;io
void printElem(int &elem)
{
cout<<elem<<endl;
}form
int main(int argc,char *argv[])
{
int a[]={1,2,-5,-7,8,-9};
vector<int> vi(a,a+sizeof(a)/sizeof(int));
transform(vi.begin(),vi.end(),vi.begin(),[](int i){return i<0?-i:i;});
for_each(vi.begin(),vi.end(),printElem);stream
return 0;
}transform
//用輸出流迭代器在每一個數後添加"#"
#include<iostream>
#include<iterator>
#include<vector>
using namespace std;
int main(int argc,char *argv[])
{
ostream_iterator<int> out_iter(cout,"#");
int a[]={1,2,3,4,5,6};
vector<int> vi(a,a+6);
for(int i=0;i<6;i++)
*out_iter++=vi[i];
cout<<endl;
return 0; }