Issue with set's in STL .
Difference between en1 and en2, changed 34 character(s)
Hello CF Community,↵

I am new to competitive programming and recently have been learning STL ,I wanted to ask that if i want to erase the smallest value and also keep on iterating, if I am writing the following code, I am getting garbage values.↵

I know that there are other ways to do this but I wanted a modification of my code ,and also I wanted to know that is it not possible to traverse set while simultaneously erasing elements.↵
<c
<spoiler summary="C
ode">↵

set <int> s;↵
s.insert(1);s.insert(2);s.insert(3);↵
for(auto it=s.begin();it!=s.end();it++)↵
{↵
cout<<*it<<endl;↵
s.erase(it);↵
}↵
</code
</spoiler
>↵

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English hacker696969 2020-06-16 22:38:11 34
en1 English hacker696969 2020-06-16 22:37:00 623 Initial revision (published)