I crated a program that is supposed to add objects to a vector and the print them, however when i add objects it only prints the last object added, i cant seem to find the error this is what i have:
#include <vector>
#include <iostream>
#include <string>
int main() {
  std::vector<GroceryItem*> item;
  GroceryItem* grocery = new GroceryItem;
  std::string option = " ";
  while((option != "x") && (option != "X")){
    std::cout << "Welcome to Kroger\n";
    std::cout << "A- add item\n";
    std::cout << "X - Exit\n";
    std::cout << "type option:";
    std::cin >> option;
    std::cin.ignore();
        if(option == "A" || option == "a") {
          std::cout << "Enter UPC, Product Brand, Product Name, and Price\n";
          std::string item_;
          double price_ = 0.0;
          std::getline(std::cin, item_);
          grocery->upcCode(item_);
          std::getline(std::cin, item_);
          grocery->brandName(item_);
          std::cin.ignore();
          std::getline(std::cin, item_);
          grocery->productName(item_);
          std::cin >> price_;
          grocery->price(price_);
          item.push_back(grocery);
        } else if(option == "x" || option == "X") {
          std::cout << "Here is an itemized list of the items in your shopping basket:\n";
          for (GroceryItem* gcry  : item) {
            std::cout << *gcry;
          }
         }
        }
      }
this is the overloaded extraction operator declared on .cpp
std::ostream& operator<<( std::ostream& stream, const GroceryItem& groceryItem ) {
  stream << "\"" << groceryItem.upcCode() << "\", " << "\"" << groceryItem.brandName() << ", "
   << groceryItem.productName() << ", " << groceryItem.price() << "\n";
   return stream;
this is a sample output:
Welcome to Kroger
A- add item
X - Exit
type option:a
Enter UPC, Product Brand, Product Name, and Price
2134567890
heinz
ketchup
222
Welcome to Kroger
A- add item
X - Exit
type option:a
Enter UPC, Product Brand, Product Name, and Price
2345678
coca cola
coke
3.33
Welcome to Kroger
A- add item
X - Exit
type option:x
Here is an itemized list of the items in your shopping basket:
"2345678", "coca cola, oke, 3.33
"2345678", "coca cola, oke, 3.33
 
     
    