fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. template <typename Iterator>
  7. void print_container(const Iterator& from, const Iterator& to)
  8. {
  9. bool first = true;
  10. for (Iterator it = from; it != to; ++it)
  11. {
  12. if (!first)
  13. cout << ", ";
  14. first = false;
  15. cout << *it;
  16. }
  17. cout << endl;
  18. }
  19.  
  20. int main()
  21. {
  22. int a[] = { 1, 2, 3 };
  23. vector<int> v = { 11, 12, 13 };
  24.  
  25. print_container(&a[0], &a[0] + (sizeof(a) / sizeof(a[0])));
  26. print_container(begin(a), end(a));
  27. print_container(begin(v), end(v));
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
1, 2, 3
1, 2, 3
11, 12, 13