fork(1) download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. struct T{
  7. string name;
  8. T(string n):name(n){};
  9. bool operator < ( const T &n ) const {
  10. return name < n.name;
  11. }
  12. };
  13.  
  14.  
  15. int main() {
  16.  
  17. vector<T> t;
  18. t.push_back(T("one"));
  19. t.push_back(T("three"));
  20. t.push_back(T("two"));
  21.  
  22. bool has_3 = binary_search( t.begin(), t.end(), T("two") ) ;
  23. if( has_3 ){
  24. cout <<"Its there" << endl;
  25. }
  26.  
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Its there