home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 May / PCP163A.iso / Runimage / Cbuilder4 / Examples / StdLib / STL_EX.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-26  |  1.7 KB  |  66 lines

  1. //---------------------------------------------------------------------------
  2. // Borland C++Builder
  3. // Copyright (c) 1987, 1998 Borland International Inc.  All Rights Reserved.
  4. //---------------------------------------------------------------------------
  5. /* Standard C++ library examples */
  6.  
  7. #include "std1.h"
  8. #include <algorithm>
  9. #include <bitset>
  10. #include <complex>
  11. #include <ctype.h>
  12. #include <deque>
  13. #include <fstream.h>
  14. #include <functional>
  15. #include <iomanip.h>
  16. #include <iostream.h>
  17. #include <iterator>
  18. #include <limits>
  19. #include <list>
  20. #include <map>
  21. #include <memory>
  22. #include <numeric>
  23. #include <queue>
  24. #include <set>
  25. #include <stack>
  26. #include <stdexcept>
  27. #include <string.h>
  28. #include <string>
  29. #include <strstrea.h>
  30. #include <utility>
  31. #include <vector>
  32.  
  33. using namespace std;
  34.  
  35. extern int ct;  // counter for current memo line
  36.  
  37.  int accum_ex () /* accum */
  38.  {
  39.    //
  40.    // Typedef for vector iterators.
  41.    //
  42.    Form1->Memo1->Lines->Strings[ct++] = " ========== Accumulator Example =========";
  43.    typedef vector<int>::iterator iterator;
  44.    //
  45.    // Initialize a vector using an array of integers.
  46.    //
  47.    int d1[10] = {1,2,3,4,5,6,7,8,9,10};
  48.    vector<int> v1(d1+0, d1+10);
  49.    //
  50.    // Accumulate sums and products.
  51.    //
  52.    int sum  = accumulate(v1.begin(), v1.end(), 0);
  53.    //
  54.    // Output the results.
  55.    //
  56.    Form1->Memo1->Lines->Strings[ct++] = "For the series: ";
  57.    for(iterator i = v1.begin(); i != v1.end(); i++)
  58.       Form1->Memo1->Lines->Strings[ct] =
  59.           Form1->Memo1->Lines->Strings[ct] + IntToStr(*i) + " ";
  60.    ct++;
  61.    Form1->Memo1->Lines->Strings[ct++] = " where N = 10.";
  62.    Form1->Memo1->Lines->Strings[ct++] = "The sum = (N*N + N)/2 = " +IntToStr(sum);
  63.  
  64.    return 0;
  65.  }
  66.