How to Find the First Element in a Set in C++? Last Updated : 26 Feb, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report In C++, a set is a container that stores unique elements following a specific order. In this article, we will learn how to find the first element in a set. Example: Input: mySet = {1, 2, 4, 3, 8, 4, 7, 8, 6, 4} Output: First Element = 1Find the First Element in a Set in C++To find the first element in a std::set in C++, we can use the std::set::begin() function that returns an iterator pointing to the first element of the set. We can dereference this iterator to get the first element in the set. C++ Program to Find the First Element in a Set C++ // C++ Program to Find the First Element from vector #include <iostream> #include <set> using namespace std; int main() { set<int> mySet = { 3, 1, 4, 1, 5, 9, 2, 6 }; // Finding the first element in the set auto firstElement = mySet.begin(); cout << "First element: " << *firstElement << endl; return 0; } OutputFirst element: 1 Time complexity: O(1)Space complexity: O(1) Comment More infoAdvertise with us Next Article How to Find First Occurrence of an Element in a Set in C++? A anuragvbj79 Follow Improve Article Tags : C++ Programs C++ STL cpp-set CPP Examples +1 More Practice Tags : CPPSTL Similar Reads How to Find the Last Element in a Set in C++? In this article, we will learn how to find the last element is a set in C++.The most efficient way to find the last element of set is by using set rbegin() function. Letâs take a look at a simple example:C++#include <bits/stdc++.h> using namespace std; int main() { set<int> s = {1, 3, 4, 2 min read How to Find the Frequency of an Element in a Set in C++? C++ STL provides a set container that can be used to store unique elements in a sorted order. In this article, we will learn how to find the frequency of an element in a set in C++. Example: Input:set<int>s ={10,20,30,40,50}Output:Frequency of 30 is 1Finding Frequency of an Element in a Set in 2 min read How to Find the Minimum Element in a List in C++? In C++, a list is a sequence container provided by the STL library that stores data in non-contiguous memory locations efficiently. In this article, we will learn how to find the minimum element in a list in C++. Example: Input: myList = {30, 10, 20, 50, 40};Output: The minimum element in the list i 2 min read How to Find First Occurrence of an Element in a List in C++? In C++, the list is a sequence container that stores data in non-contiguous memory allocation. It is defined in the STL (Standard Template Library) inside the <list> header. In this article, we will learn how to find the first occurrence of a specific element in a list in C++. Example: Input: 2 min read How to Find First Occurrence of an Element in a Set in C++? In C++, a set is an ordered container that stores its unique values in some given order. In this article, we will see how to find the first occurrence of a specific element in a set in C++ STL. For Example, Input: mySet = {1, 2, 3, 8, 9, 11} Target = 9 Output: Element found at Index: 4Find the First 2 min read How to Find the Frequency of an Element in a Multiset in C++? In C++, a multiset is a container that stores elements in a sorted order and multiple elements can have the same values. In this article, we will learn how to find the frequency of a specific element in a multiset. Example: Input: myMultiset = { 5,2,8,5,8,8} Element: 8 Output: Frequency of 8 is: 3Fi 2 min read Like