24.4.3 Searching Algorithms - binary_search (cont.)

vector<int> a(20);
generate(a.begin(), a.end(), RandomInt(1, 10));
sort(a.begin(), a.end());
if (binary_search(a.begin(), a.end(), 7))
{
   vector<int>::iterator p
      = lower_bound(a.begin(), a.end(), 7);
   vector<int>::iterator q
      = upper_bound(a.begin(), a.end(), 7);
   while (p != q)
   {
      cout << "found " << *p << "\n";
      ++p;
   }
}

prev |top |next