Руководство по стандартной библиотеке шаблонов STL

       

did not find 42"


#include <stl.h> #include <iostream.h>

int main () { int vector[100]; for (int i = 0; i < 100; i++) vector[i] = i; if (binary_search (vector, vector + 100, 42)) cout << "found 42" << endl; else cout << " did not find 42" << endl; return 0; }



#include <stl.h> #include <iostream.h> #include <string.h>

bool str_compare ( const char* a_, const char* b_) { return ::strcmp (a_, b_) < 0 ? 1 : 0; }

char* labels[] = { "aa", "dd", "ff", "jj", "ss", "zz" };

int main () { const unsigned count = sizeof (labels) / sizeof (labels[0]); if (binary_search (labels, labels + count, "ff", str_compare)) cout << "ff is in labels." << endl; else cout << "ff is not in labels." << endl; return 0; }


Содержание раздела