Advertisement
RobertDeMilo

WB2.11 Множества 1

Sep 4th, 2023
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3.  
  4. using namespace std;
  5.  
  6. void PrintSet(const set <string>& s)
  7. {
  8.     cout << "Size = " << s.size() << endl;
  9.  
  10.     for (auto x : s) // перестали копировать очередную пару ключ - значение в переменную item c помощью константной ссылки
  11.     {
  12.         cout << x << endl;
  13.     }
  14. }
  15.  
  16. int main()
  17. {
  18.     set<string> famous_persons;
  19.  
  20.     famous_persons.insert("Stroustrup");
  21.     famous_persons.insert("Ritchie");
  22.     famous_persons.insert("Anton");
  23.     PrintSet(famous_persons);
  24.  
  25.     famous_persons.erase("Anton");
  26.     PrintSet(famous_persons);
  27.  
  28.     return 0;
  29. }
  30.  
Tags: insert erase
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement