[C++] A mistake when I delete an element in STL set.

Revision en1, by hongjun-7, 2017-10-25 09:49:21
int main() {
	{
		//Wrong
		set  s = {1,2,3,4,5};
		auto it = s.lower_bound(3);
		s.erase(it);
		it++;
		printf("%d\n", *it);
	} {
		//Correct 1
		set  s = {1,2,3,4,5};
		auto it = s.lower_bound(3);
		s.erase(it++);
		printf("%d\n", *it);
	} {
		//Correct 2
		set  s = {1,2,3,4,5};
		auto it = s.lower_bound(3);
		it = s.erase(it);
		printf("%d\n", *it);
	}
}
Tags set

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English hongjun-7 2017-10-25 09:50:17 13
en1 English hongjun-7 2017-10-25 09:49:21 482 Initial revision (published)