home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C21 / MemFun4.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  851 b   |  31 lines

  1. //: C21:MemFun4.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Using the SGI STL compose1 function
  7. #include "NumStringGen.h"
  8. #include <algorithm>
  9. #include <vector>
  10. #include <string>
  11. #include <iostream>
  12. #include <functional>
  13. using namespace std;
  14.  
  15. int main() {
  16.   const int sz = 9;
  17.   vector<string> vs(sz);
  18.   // Fill it with random number strings:
  19.   generate(vs.begin(), vs.end(), NumStringGen());
  20.   copy(vs.begin(), vs.end(), 
  21.     ostream_iterator<string>(cout, "\t"));
  22.   cout << endl;
  23.   vector<double> vd;
  24.   transform(vs.begin(), vs.end(), back_inserter(vd),
  25.     compose1(ptr_fun(atof), 
  26.       mem_fun_ref(&string::c_str)));
  27.   copy(vd.begin(), vd.end(), 
  28.     ostream_iterator<double>(cout, "\t"));
  29.   cout << endl;
  30. } ///:~
  31.