Wondeirng why below code returns 1? I never insert 1 into the multiset container.
#include <iostream>
#include <set>
int main ()
{
std::multiset<int> mymultiset;
std::multiset<int>::iterator itlow;
mymultiset.insert(-3);
itlow = mymultiset.lower_bound (3);
std::cout << *itlow << endl; // output 1
return 0;
}
mymultiset.lower_bound(3)returns the lowest location in the container where3could go, and that's at the end of the container. Soitlowis equal tomymultiset.end(), and it is not dereferenceable.std::cout << *itlowhas undefined behavior.