How to Create a Set of Sets in C++? Last Updated : 19 Feb, 2024 Comments Improve Suggest changes Like Article Like Report In C++, sets are STL containers that store unique elements of the same type in a sorted manner. Sets of sets, also known as nested sets, are collections in which each element of the outer set contains another set as its element. In this article, we will learn how to create a set of sets in C++. Set of Sets in C++You can create a set of sets by defining the type of the outer set as another set with a given data type. It will create a set where each element of this set will be a set in itself. Syntax to Create a Set of Setsset< set<type> > mySetOfSet; C++ Program to Create a Set of Set C++ // C++ program to create a set of Set #include <iostream> #include <set> using namespace std; // Driver Code int main() { // Creating a set of sets set<set<int> > setOfSets; // creating sets to insert set<int> set1 = { 1, 2, 3 }; set<int> set2 = { 2, 3, 4 }; set<int> set3 = { 3, 4, 5 }; // Adding sets to the set of sets setOfSets.insert(set1); setOfSets.insert(set2); setOfSets.insert(set3); // Displaying the sets in the set of sets for (const auto& innerSet : setOfSets) { for (const auto& element : innerSet) { cout << element << " "; } cout << endl; } return 0; } Output1 2 3 2 3 4 3 4 5 Time Complexity: O(N2)Auxilairy Space: O(N2) Comment More infoAdvertise with us Next Article How to Create a Set of Sets in C++? L lucifer2411 Follow Improve Article Tags : C++ Programs C++ STL cpp-set CPP Examples +1 More Practice Tags : CPPSTL Similar Reads How to Create a Stack of Set in C++? In C++ STL, Stacks are a type of container adaptor with LIFO(Last In First Out) type of working, where a new element is added at one end (top) and an element is removed from that end only. Sets are a type of associative container in which each element is unique and in some sorted order. In this arti 2 min read How to Create a Set of Pairs in C++? In C++, sets are associative containers that store unique elements. On the other hand, pairs allow the users to store two data of different or the same type into a single object. In this article, we will learn how we can create a set of pairs in C++. Example Input: p1={1, 2} p2 ={3, 4} Output: Eleme 2 min read How to Create a Set of Vectors in C++? In C++, a set is a type of associative container in which duplicate elements are not allowed and a vector is a dynamic array in which duplicate elements are allowed. In this article, we will learn how to create a set of vectors in C++. For Example, Input:vector<int> vec1={1, 2, 3};vector<in 2 min read How to Create a Deque of Sets in C++? In C++, a container called deque is a queue like container but allows for fast insertions and deletions at both ends. In this article, we will learn how to create a deque of sets in C++. Example: Input: mySet1 = {1, 4, 8, 9, 11} mySet2 = {1, 2, 3, 5, 7} Output: myDeque: [ {1, 4, 8, 9, 11}, {1, 2, 3, 2 min read How to Create a Set of Arrays in C++? In C++, the set container represents a collection of unique, sorted elements, and an array is a collection of items stored at contiguous memory locations. In this article, we will learn about how to create a set of arrays in C++. Set of Arrays in C++A set of arrays refers to a collection of arrays w 2 min read Like