Sets and Maps in C++
Introduction
Both sets and maps are known as associative containers, which is an abstract data type that stores a collection of unique, ordered values. Where they differ is that sets store values
Using std::set
To use std::set, remember to include it into your project by adding #include set
to the top of your cpp/header file. Then, it can be used like the below example:
#include <iostream>
#include <set>
int main(int argc, char** argv) {
std::set integerSet = {4, 2, 2, 6};//This will become {2, 4, 6}
for (int i: integerSet) {
std::cout << i << '\n';
}
std::cout.flush();
}
This results in the following output:
2
4
6