shushus

Спринт 2. Универсальные функции вывода контейнеров. Задание 3.

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