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 160 views
2 answers 124 views
124 views asked Oct 21, 2022 by avibootz
1 answer 106 views
106 views asked Oct 20, 2022 by avibootz
1 answer 300 views
2 answers 127 views
2 answers 159 views
2 answers 166 views
...