fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <string>
  5.  
  6.  
  7. struct element
  8. {
  9. std::string name;
  10. };
  11.  
  12. //Type of container
  13. std::vector<element> elementVctr;
  14.  
  15. using namespace std;
  16.  
  17. string foo(const std::string& nameToFind)
  18. {
  19. auto it = find_if(elementVctr.begin(), elementVctr.end(),
  20. [&](const element& e ) { return e.name == nameToFind; });
  21. if ( it != elementVctr.end() )
  22. return it->name;
  23. return "";
  24. }
  25.  
  26. int main()
  27. { }
Success #stdin #stdout 0s 3092KB
stdin
Standard input is empty
stdout
Standard output is empty