problem with finding an element in a set?

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <functional>
#include <set>
using namespace 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

Replace greater_equal with greater in the template argument
Topic archived. No new replies allowed.