How to Check if a Set is Empty in C++? Last Updated : 29 Feb, 2024 Comments Improve Suggest changes Like Article Like Report In C++, a set is an associative container that stores unique elements in a sorted order. In this article, we'll explore different approaches to check if a set is empty in C++ STL. Check if a Set is Empty or Not in C++To check if a std::set is empty in C++, we can use the std::set::empty() function. This function returns a boolean value indicating whether the set is empty. C++ Program to Check if a Set is Empty C++ // C++ Program to show how to check if a set is empty or not #include <iostream> #include <set> using namespace std; int main() { // Creating sets named 'mySet1' and 'mySet2' set<int> mySet1; set<int> mySet2 = { 1, 2 }; // Checking if mySet1 is empty if (mySet1.empty()) { cout << "Set1 is empty." << endl; } else { cout << "Set1 is not empty." << endl; } // Checking if mySet1 is empty if (mySet2.empty()) { cout << "Set2 is empty." << endl; } else { cout << "Set2 is not empty." << endl; } return 0; } // This code is contributed by Susobhan Akhuli OutputSet1 is empty. Set2 is not empty. Time Complexity: O(1)Auxiliary Space: O(1) The set container in C++ STL provides an size() member function that returns the size (or number of elements) of the set. We can also check is a set is empty or not using size() function in C++ because if the size is 0, then the set is empty otherwise not. Comment More infoAdvertise with us Next Article How to Check if a Set is Empty in C++? S susobhanakhuli19 Follow Improve Article Tags : C++ Programs C++ STL cpp-set CPP Examples +1 More Practice Tags : CPPSTL Similar Reads How to Check if a List is Empty in C++? In C++, a list is a sequence container that allows non-contiguous memory allocation and is implemented using a doubly linked list. In this article, we will learn how to check if a list is empty in C++. Example: Input: myList = {1, 2, 3}; Output: List is not empty.Check if a List is Empty in C++To ch 2 min read How to Check if a Stack is Empty in C++? In C++, we have a stack data structure that follows a LIFO (Last In First Out) rule of operation. In this article, we will learn how to check if a stack is empty in C++. Example:Input:myStack = {1, 2, 3 } Output:Stack is not EmptyChecking if a Stack is Empty in C++To check if a stack is empty in C++ 2 min read How to Check if a String is Empty in C++? In C++, strings are the sequence of characters that are stored as std::string class objects. In this article, we will learn how to check if a string is empty in C++ Example Input: str1="Hello! Geek" ; str2="" Output: str1 is not empty str2 is emptyChecking if the String is Empty in C++To check for a 2 min read How to Check if a Map is Empty in C++? In C++, a map is an associative container that stores elements as key-value pairs and an empty map means it contains no elements. In this article, we will learn how to check if a map is empty or not in C++. Example: Input: map<int,string>mp1 = {{1, "Ram"}, {2, "Mohit"}};map<int,string> m 2 min read How to Check if a Vector is Empty in C++? A vector is said to be empty when there are no elements present in vector. In this article, we will learn different ways to check whether a vector is empty or not.The most efficient way to check if the vector is empty or not is by using the vector empty() function. Letâs take a look at a simple exam 2 min read Like