Odd values printed when dereferencing the end iterator of a vector
问题 I have a vector storing {1,2,3,4,5}. I tried to print *(vec.end()) and got back the result 6. I don't know how to explain this. Similarly, calling vec.find(500) gave the result 6. Why am I getting this number? #include<iostream> #include<iterator> #include<set> #include<map> int main() { int a[] = {1,2,3,4,5}; std::set<int> set1(a,a+sizeof(a)/sizeof(int)); for (std::set<int>::iterator itr=set1.begin();itr!=set1.end();++itr){ std::cout << *itr << std::endl; } //std::pair<std::set<int>: