Under g++ when I compile the following code I receive an unexpected result. The intentions of this code is to initialize a set, find a certain element and display it accordingly.
#include <iostream>
#include <functional>
#include <set>
usingnamespace std;
//typeddef(s)
typedef set<int, greater_equal<int> > TIntSet;
int main()
{
//initialize set
int intBuf[5] = {0, 1, 2, 3, 4};
TIntSet intSet(intBuf, intBuf + 5);
//return iterator to element 3
TIntSet::iterator i;
i = intSet.find(3);
//displaying key
cout << *i << endl; //display 5 instead of 3, error
return 0;
}
//output: 5
The trouble here is that the result returns 5, that is the member function find is unable to find element 3 and returns the past-the-end value even though the object intSet has been explicitly initialized with 0,1,2,3,4. Any insight into debugging this problem would be great