# Set of Vectors in C++ STL with Examples

Set in STL Sets are a type of associative containers in which each element has to be unique, because the value of the element identifies it. The value of the element cannot be modified once it is added to the set, though it is possible to remove and add the modified value of that element.

Vector in STL Vector is same as dynamic arrays with the ability to resize itself automatically when an element is inserted or deleted, with their storage being handled automatically by the container. Vector elements are placed in contiguous storage so that they can be accessed and traversed using iterators.

Set of Vectors in STL: Set of Vectors can be very efficient in designing complex data structures.

Syntax:

```set<vector<datatype>> set_of_vector;
```

For example: Consider a simple problem where we have to print all the unique vectors.

 `// C++ program to demonstrate ` `// use of set for vectors ` ` `  `#include ` `using` `namespace` `std; ` ` `  `set > set_of_vectors; ` ` `  `// Print elements of Vector ` `void` `Print_Vector(vector<``int``> Vec) ` `{ ` `    ``for` `(``int` `i = 0; i < Vec.size(); i++) { ` `        ``cout << Vec[i] << ``" "``; ` `    ``} ` `    ``cout << endl; ` `    ``return``; ` `} ` ` `  `// Driver code ` `int` `main() ` `{ ` `    ``// Initializing some vectors ` `    ``vector<``int``> data_1{ 10, 20, 30, 40 }; ` `    ``vector<``int``> data_2{ 5, 10, 15 }; ` `    ``vector<``int``> data_3{ 1, 3, 5, 7, 9, 11, 13 }; ` `    ``vector<``int``> data_4{ 5, 10, 15 }; ` `    ``vector<``int``> data_5{ 10, 20, 30, 40 }; ` ` `  `    ``// Inserting vectors into set ` `    ``set_of_vectors.insert(data_1); ` `    ``set_of_vectors.insert(data_2); ` `    ``set_of_vectors.insert(data_3); ` `    ``set_of_vectors.insert(data_4); ` `    ``set_of_vectors.insert(data_5); ` ` `  `    ``// printing all the unique vectors in set ` `    ``cout << ``"Set of Vectors: \n"``; ` `    ``for` `(``auto` `it = set_of_vectors.begin(); ` `         ``it != set_of_vectors.end(); ` `         ``it++) { ` ` `  `        ``Print_Vector(*it); ` `    ``} ` ` `  `    ``return` `0; ` `} `

Output:

```Set of Vectors:
1 3 5 7 9 11 13
5 10 15
10 20 30 40
```

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

4

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.