Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. template <typename T>
  5. std::ostream& operator <<(std::ostream& text, const std::vector<T>& vec) {
  6.     if (vec.empty()) {
  7.         return text << "[]";
  8.     }
  9.  
  10.     auto current = vec.begin();
  11.     auto last = --vec.end();
  12.  
  13.     text << '[';
  14.  
  15.     for (; current != last; ++current) {
  16.         text << *current << ", ";
  17.     }
  18.  
  19.     return text << *last << ']';
  20. }
  21.  
  22. int main() {
  23.     std::vector<int> vec = {1, 2, 3};
  24.  
  25.     std::cout << vec;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement