fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. struct Track
  6. {
  7. Track(){}
  8. Track(int d, std::string t) : duration(d), title(t) {}
  9. int duration;
  10. std::string title;
  11. };
  12.  
  13. std::ostream& operator<<(std::ostream& o, const Track& t)
  14. {
  15. return o <<"Track[ " << t.title << ", " << t.duration << "]";
  16. }
  17.  
  18. std::ostream& operator<<(std::ostream& o, const std::vector<Track>& v)
  19. {
  20. for (std::vector<Track>::const_iterator it = v.begin(); it != v.end(); ++it) {
  21. o << *it << " ";
  22. }
  23. return o;
  24. }
  25.  
  26. int main()
  27. {
  28. std::vector<Track> v;
  29. v.push_back(Track(55, "Hairway to Steven"));
  30. v.push_back(Track(23, "A boy named Sue"));
  31. std::cout << v << "\n";
  32. }
Success #stdin #stdout 0.01s 2816KB
stdin
Standard input is empty
stdout
Track[ Hairway to Steven, 55] Track[ A boy named Sue, 23]