home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stl2vac.zip / STLport-4_5_3.zip / STLport-4.5.3 / test / regression / adjfind2.cpp < prev    next >
C/C++ Source or Header  |  2000-12-07  |  1KB  |  44 lines

  1. // STLport regression testsuite component.
  2. // To compile as a separate example, please #define MAIN.
  3.  
  4. #include <string>
  5. #include <vector>
  6. #include <algorithm>
  7. #include <iostream>
  8.  
  9. #ifdef MAIN 
  10. #define adjfind2_test main
  11. #endif
  12.  
  13. #if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
  14. using namespace std;
  15. #endif
  16. static int equal_length(const char* v1_, const char* v2_)
  17. {
  18.   return ::strlen(v1_) == ::strlen(v2_);
  19. }
  20. int adjfind2_test(int, char**)
  21. {
  22.   cout<<"Results of adjfind2_test:"<<endl;
  23. typedef vector <char*> CStrVector;
  24.  
  25. char* names[] = { "Brett", "Graham", "Jack", "Mike", "Todd" };
  26.  
  27.   const int nameCount = sizeof(names)/sizeof(names[0]);
  28.   CStrVector v(nameCount);
  29.   for(int i = 0; i < nameCount; i++)
  30.     v[i] = names[i];
  31.   CStrVector::iterator location;
  32.   location = adjacent_find(v.begin(), v.end(), equal_length);
  33.   if(location != v.end())
  34.     cout
  35.       << "Found two adjacent strings of equal length: "
  36.       << *location
  37.       << " -and- "
  38.       << *(location + 1)
  39.       << endl;
  40.   else
  41.     cout << "Didn't find two adjacent strings of equal length.";
  42.   return 0;
  43. }
  44.