In C++, you can use the empty()
method of the standard library's Set container to check if it's not empty.
In this example,
std::set
container from the C++ standard library and initialize it with some elements.empty()
method on the Set to determine if it contains any elements.empty()
method returns false
; otherwise, it returns true
.#include <iostream>
#include <set>
int main() {
std::set<int> mySet = {1, 2, 3}; // Or std::set<int> mySet;
if (!mySet.empty()) {
std::cout << "The Set is not empty\n";
} else {
std::cout << "The Set is empty\n";
}
return 0;
}
The Set is not empty
In this example,
std::set
container.empty()
method on the Set to determine if it contains any elements.empty()
method returns true
.#include <iostream>
#include <set>
int main() {
std::set<int> emptySet;
if (!emptySet.empty()) {
std::cout << "The Set is not empty\n";
} else {
std::cout << "The Set is empty\n";
}
return 0;
}
The Set is empty
In this tutorial, we learned How to check if a Set is Not Empty in C++ language with well detailed examples.