How to Create a Set of Vectors in C++? Last Updated : 22 Feb, 2024 Comments Improve Suggest changes Like Article Like Report 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<int> vec2={4, 5, 6};vector<int> vec3={1, 2, 3};Output:Set Elements are:{1 2 3}{4 5 6} Declaring a Set of Vectors in C++To create a set of vectors, first declare a std::set with std::vector<dataType> as its template parameter and then add the vectors to the set using set::insert() method. Syntax to Declare Set of Vectors in C++set<vector<datatype>> setOfVector;In the above set, each element will be a vector of type 'datatype' C++ Program to Create a Set of Vectors C++ // C++ program to create set for vectors #include <iostream> #include <set> #include <vector> using namespace std; int main() { // Creating set of vectors // that will store each vector set<vector<int> > st; // Initializing vectors vector<int> vec1{ 1, 2, 3 }; vector<int> vec2{ 4, 5, 6 }; vector<int> vec3{ 1, 2, 3 }; // Inserting the above vectors into the set st.insert(vec1); st.insert(vec2); st.insert(vec3); // Iterating and printing vectors from the set cout << "Set Elements are: " << endl; for (auto& it : st) { for (int elem : it) { cout << elem << " "; } cout << endl; } return 0; } OutputSet Elements are: 1 2 3 4 5 6 Time Complexity: O(N * M log N), here N is the number of vectors in the set and M is the average size of the vectors.Auxiliary Space: O(N * M) Comment More infoAdvertise with us Next Article How to Create a Set of Vectors in C++? S sireeshakanneganti112 Follow Improve Article Tags : C++ Programs C++ STL cpp-vector cpp-set CPP Examples +2 More Practice Tags : CPPSTL Similar Reads How to Create a Stack of Vectors in C++? In C++, a stack of vectors can be created using the Standard Template Library (STL). The stack is a container adapter that provides a Last-In-First-Out (LIFO) type of data structure, and a vector is a dynamic array that can grow and shrink in size. In this article, we will learn how to create a stac 2 min read How to Create a Vector of Pairs in C++? In C++, std::pair is the data type that stores the data as keys and values. On the other hand, std::vector is an STL container that stores the collection of data of similar type in the contiguous memory location. In this article, we will learn how to combine these two to create a vector of pairs in 5 min read How to Create a Set of Sets in C++? 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 2 min read How to Create a Vector of Tuples in C++? In C++, a tuple is an object that allows the users to store elements of various data types together while a vector is used to store elements of the same data types. In this article, we will learn how we can create a vector of tuples in C++. Example: Input: Tuple1 ={10,A,5.3} Tuple2= {20,B,6.5}Output 2 min read How to Create a Deque of Vectors in C++? In C++, deques are sequence containers similar to queues but unlike queues, deques allow the insertion and deletion of elements from both ends efficiently. Vectors are dynamic arrays that can resize themselves during the runtime. In this article, we will learn how to create a deque of vectors in C++ 2 min read Like