Standard C++ Library Class Reference
bool b2 = binary_search(v1.begin(),v1.end(),11,less<int>());
//
// Output results
//
cout << "In the vector: ";
copy(v1.begin(),v1.end(),
ostream_iterator<int>(cout," "));
cout << endl << "The number 3 was "
<< (b1 ? "FOUND" : "NOT FOUND");
cout << endl << "The number 11 was "
<< (b2 ? "FOUND" : "NOT FOUND") << endl;
return 0;
}
Output :
In the vector: 0 1 2 2 2 2 3 4 6 7
The number 3 was FOUND
The number 11 was NOT FOUND
Warnings
If your compiler does not support default template parameters, then you need to always supply
the Allocator template argument. For instance, you'll have to write:
vector<int,allocator>
instead of:
vector<int>
See Also
equal_range, lower_bound, upper_bound