fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. struct grocery{
  9. string name;
  10. string expdate;
  11. string price;
  12. };
  13.  
  14. int main(){
  15. grocery tempProd;
  16. string tempStr;
  17. vector<grocery> produce;
  18.  
  19. cout << "What grocery product are you looking for?";
  20. getline(cin, tempStr);
  21. auto it = std::find_if (produce.begin(), produce.end(), [&] (const grocery &g) {return g.name == tempStr;});
  22. if (it != produce.end()){
  23. cout << "Product has been found!" << endl;
  24. cout << "What is going to be the new price of the product?";
  25. string tempStr2;
  26. getline(cin, tempStr2);
  27. it->price = tempStr2;
  28. }
  29. else{
  30. cout << "Product does not exist." << endl;
  31. }
  32. }
Success #stdin #stdout 0s 5568KB
stdin
Standard input is empty
stdout
What grocery product are you looking for?Product does not exist.