shizaero

Универсальные функции вывода контейнеров / Задание № 2

Jan 11th, 2023
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. template <typename Element>
  7. ostream& operator<<(ostream& out, const vector<Element>& container) {
  8.     bool is_first = true;
  9.     for (const auto& element : container) {
  10.         if (!is_first) {
  11.             out << ", "s;
  12.         }
  13.         is_first = false;
  14.         out << element;
  15.     }
  16.     return out;
  17. }
  18.  
  19. int main() {
  20.     const vector<int> ages = {10, 5, 2, 12};
  21.     cout << ages << endl;
  22. }
Add Comment
Please, Sign In to add comment