fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. class Ingredient
  7. {
  8. public:
  9. Ingredient() = default;
  10. Ingredient(std::string name, std::string first, std::string second, std::string third, std::string fourth) :
  11. iName(std::move(name)),
  12. pAttr(std::move(first)),
  13. sAttr(std::move(second)),
  14. tAttr(std::move(third)),
  15. qAttr(std::move(fourth))
  16. {
  17. }
  18.  
  19. const std::string& getName() const
  20. {
  21. return iName;
  22. }
  23.  
  24. void displayIngredient() const
  25. {
  26. std::cout << '\n';
  27. std::cout << "Ingredient: " << iName << '\n';
  28. std::cout << "Primary Effect: " << pAttr << '\n';
  29. std::cout << "Secondary Effect: " << sAttr << '\n';
  30. std::cout << "Tertiary Effect: " << tAttr << '\n';
  31. std::cout << "Quaternary Effect: " << qAttr << '\n';
  32. }
  33.  
  34. private:
  35. std::string iName;
  36. std::string pAttr;
  37. std::string sAttr;
  38. std::string tAttr;
  39. std::string qAttr;
  40. };
  41.  
  42. int main()
  43. {
  44. std::vector<Ingredient> satchel;
  45. satchel.reserve(3);
  46. satchel.emplace_back("White Cap", "Weakness to Frost", "Fortify Heavy Armor", "Restore Magicka", "Ravage Magicka");
  47. satchel.emplace_back("Wisp Wrappings", "Restore Stamina", "Fortify Destruction", "Fortify Carry Weight", "Resist Magic");
  48. satchel.emplace_back("Yellow Mountain Flower", "Resist Poison", "Fortify Restoration", "Fortify Health", "Damage Stamina Regen");
  49.  
  50. const auto ingredientFoundByName = std::find_if(satchel.begin(), satchel.end(),
  51. [&](const Ingredient& currIngredient)
  52. {
  53. return currIngredient.getName() == "Yellow Mountain Flower";
  54. });
  55.  
  56. if (ingredientFoundByName != satchel.end())
  57. {
  58. ingredientFoundByName->displayIngredient();
  59. }
  60. else
  61. {
  62. std::cout << "Could not find ingredient\n";
  63. }
  64.  
  65. return EXIT_SUCCESS;
  66. }
Success #stdin #stdout 0s 15248KB
stdin
Standard input is empty
stdout
Ingredient: Yellow Mountain Flower
Primary Effect: Resist Poison
Secondary Effect: Fortify Restoration
Tertiary Effect: Fortify Health
Quaternary Effect: Damage Stamina Regen