fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4.  
  5. template <typename T>
  6. std::ostream& operator<< (std::ostream& out, const std::vector<T>& v) {
  7. if (!v.empty()) {
  8. auto it = v.begin();;
  9. for (; it != v.end() - 1; ++it)
  10. {
  11. out << *it << ", ";
  12. }
  13. out << *it << std::endl;
  14. }
  15. return out;
  16. }
  17.  
  18. int main()
  19. {
  20. std::vector<int> v{ 1, 2, 3, 4 };
  21.  
  22. std::cout << v;
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
1, 2, 3, 4