Praktikum_mf

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

Dec 8th, 2021
2,041
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. template <typename Element>
  8. ostream& operator<<(ostream& out, const vector<Element>& container) {
  9.     bool is_first = true;
  10.     for (const auto& element : container) {
  11.         if (!is_first) {
  12.             out << ", "s;
  13.         }
  14.         is_first = false;
  15.         out << element;
  16.     }
  17.     return out;
  18. }
  19.  
  20. template <typename Element>
  21. ostream& operator<<(ostream& out, const set<Element>& container) {
  22.     bool is_first = true;
  23.     for (const auto& element : container) {
  24.         if (!is_first) {
  25.             out << ", "s;
  26.         }
  27.         is_first = false;
  28.         out << element;
  29.     }
  30.     return out;
  31. }
  32.  
  33. int main() {
  34.     const set<string> cats = {"Мурка"s, "Белка"s, "Георгий"s, "Рюрик"s};
  35.     cout << cats << endl;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment