fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. struct Item
  7. {
  8. std::string name;
  9. double price;
  10. };
  11.  
  12. std::istream & operator >>(std::istream & is, Item & item)
  13. {
  14. is >> item.name >> item.price;
  15. return is;
  16. }
  17.  
  18. int main ()
  19. {
  20. std::vector<Item> items;
  21. Item reader;
  22. // get items
  23. while (cin >> reader)
  24. items.push_back(reader);
  25.  
  26. // display items
  27. for (const auto & e : items)
  28. std::cout << e.name << "\t" << e.price << std::endl;
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 3464KB
stdin
milk 2.5
juice 3.0
coffee 2.25
soda 1.0
stdout
milk	2.5
juice	3
coffee	2.25
soda	1