How to get the first element of set in C++

3 Answers

0 votes
#include <iostream>
#include <set>
   
int main()
{
    std::set<int> st = {12, 100, 89, 55, 45, 99, 19, 61, 70};
   
    std::set<int> :: iterator it = st.begin();

    std::cout << *it;
}
   
   
   
   
/*
run:
   
12
   
*/

 



answered Oct 21, 2022 by avibootz
0 votes
#include <iostream>
#include <set>
   
int main()
{
    std::set<int> st = {12, 100, 89, 55, 45, 99, 19, 61, 70};
   
    auto firstElement = *(st.begin()); 

    std::cout << firstElement;
}
   
   
   
   
/*
run:
   
12
   
*/

 



answered Oct 21, 2022 by avibootz
0 votes
#include <iostream>
#include <set>
   
int main()
{
    std::set<int> st = {19, 12, 100, 89, 55, 45, 99, 19, 61, 70};
   
    auto firstElement = st.begin();

    std::cout << *firstElement;
}
   
   
   
   
/*
run:
   
19
   
*/

 



answered Oct 21, 2022 by avibootz

Related questions

1 answer 174 views
2 answers 135 views
135 views asked Oct 21, 2022 by avibootz
1 answer 123 views
123 views asked Oct 20, 2022 by avibootz
1 answer 313 views
2 answers 138 views
2 answers 174 views
2 answers 184 views
...