count

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int arr[] = { 14, 12, 15, 11, 10 };
  6. // initializes the set from an array
  7. set<int> s(arr, arr + 5);
  8. // check if 11 is present or not
  9. if (s.count(11))
  10. cout << "11 is present in the set\n";
  11. else
  12. cout << "11 is not present in the set\n";
  13. // checks if 18 is present or not
  14. if (s.count(18))
  15. cout << "18 is present in the set\n";
  16. else
  17. cout << "18 is not present in the set\n";
  18. return 0;
  19. }

输出:
11 is present in the set
18 is not present in the set