transform 2

#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <iterator>

using namespace std;

int main()
{
	vector<int> ivec;
	list<int> ilist;

	for (int i = 1; i <= 9; ++i)
		ivec.push_back(i);
	for (vector<int>::iterator iter = ivec.begin(); iter != ivec.end(); ++iter)
		cout << *iter << ' ';
	cout << endl;

	transform(ivec.begin(), ivec.end(), ivec.begin(), ivec.begin(),multiplies<int>());  
	for (vector<int>::iterator iter = ivec.begin(); iter != ivec.end(); ++iter)
		cout << *iter << ' ';
	cout << endl; // 1 4 9 16 25 36 49 64 81
	
	transform(ivec.begin(), ivec.end(),
		ivec.rbegin(),
		back_inserter(ilist),
		plus<int>());
	for (list<int>::iterator iter = ilist.begin(); iter != ilist.end(); ++iter)
		cout << *iter << ' ';
	cout << endl; // 82 68 58 52 50 52 58 68 82
	


	return 0;
}

你可能感兴趣的:(transform 2)