How to remove the first element from a set in C++

1 Answer

0 votes
#include <iostream>       
#include <set> 
           
using namespace std; 
    
void printSet(set<int> st) {
    for (auto n: st) {
        cout << n << ' ' ; 
    } 
}
    
int main ()
{
    set<int> st;
    
    for (int i = 1; i <= 10; i++) 
        st.insert(i);
  
    printSet(st); 
    
    st.erase(st.begin());
    
    cout << endl; 
    printSet(st); 

    return 0;
} 
      
       
       
       
/*
run:
       
1 2 3 4 5 6 7 8 9 10 
2 3 4 5 6 7 8 9 10 
    
*/

 



answered Apr 8, 2020 by avibootz

Related questions

2 answers 164 views
1 answer 148 views
3 answers 144 views
144 views asked Oct 21, 2022 by avibootz
1 answer 214 views
1 answer 196 views
1 answer 192 views
1 answer 140 views
...