fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <iomanip>
  6. using namespace std;
  7. struct stRPC {
  8. int ID;
  9. string Name;
  10. bool Enable;
  11. stRPC(int id, string name, bool enable = false){
  12. ID = id, Name = name, Enable = enable;
  13. };
  14.  
  15. };
  16.  
  17. int main() {
  18. vector <stRPC> vec = {
  19. {0, "NaN"},
  20. {1, "TEST", true},
  21. {22, "Hello"},
  22. {2, "qwerty", false},
  23. };
  24. string search = "test";
  25. int ID = 22;
  26. bool enable = true;
  27. auto iter = find_if(vec.begin(), vec.end(), [search](const stRPC& element){
  28. return element.Name == search;
  29. });
  30. cout << "Search text \"" << search << "\" " << boolalpha << (iter != vec.end()) << endl;
  31.  
  32. iter = find_if(vec.begin(), vec.end(), [enable](const stRPC& element){
  33. return element.Enable == enable;
  34. });
  35. cout << "Search first enable \"" << enable << "\" " << (iter != vec.end() ? to_string(iter->ID).c_str() : "not find") << endl;
  36.  
  37. iter = find_if(vec.begin(), vec.end(), [ID](const stRPC& element){
  38. return element.ID == ID;
  39. });
  40. cout << "Search ID \"" << ID << "\" " << boolalpha << (iter != vec.end()) << endl;
  41. return 0;
  42. }
Success #stdin #stdout 0s 4324KB
stdin
Standard input is empty
stdout
Search text "test" false
Search first enable "true" 1
Search ID "22" true