005
13.01.2004, 00:00 Uhr
(un)wissender
Niveauwart
|
Nimm statt for_each transform, sorry dafür.
C++: |
#include <iostream> #include <iterator> #include <functional> #include <algorithm> #include <list>
int main(int agrc, char *args[]) { using namespace std; typedef int my_value; my_value adder = my_value(2); list<my_value> my_list; my_list.push_back(my_value(1)); my_list.push_back(my_value(2)); my_list.push_back(my_value(3)); //Vor Addition copy(my_list.begin(), my_list.end(), ostream_iterator<my_value>(cout, " ")); transform(my_list.begin(), my_list.end(), my_list.begin(), bind2nd(plus<my_value>(), adder ) ); cout << endl; //Nach Addition copy(my_list.begin(), my_list.end(), ostream_iterator<my_value>(cout, " "));
return 0; }
|
-- Wer früher stirbt ist länger tot. |