get first element of set c++

To get the first element of a set in C++, you can use the begin() function to obtain an iterator to the first element and then dereference the iterator to access the value.

Here's the code to achieve this:

std::set<int> mySet = {3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5};
int firstElement = *mySet.begin();

In the provided example, a set of integers is initialized with some values. Then, the begin() function is used to obtain an iterator pointing to the first element in the set. Finally, the iterator is dereferenced using the * operator to get the value of the first element, which is then assigned to the variable firstElement.