How can one get the maximum of a set?

I tried using this code to get the maximum of a set.

1
2
3
4
5
set<int> myset;
myset.insert(1);
myset.insert(3);
myset.insert(2);
cout << max(myset);


Earlier, I did #include<algorithm> and #include<set> .

However, when I compile, g++ issues this error:

error no matching function for call to 'max(std::set<int>&)'

Why does the max function not exist? I did include the algorithm library.
Last edited on
The maximum value in the set is *myset.rbegin()
Thank you! Also, I figured out that the max() in the algorithm library only takes two arguments. It's pretty pointless I think since the max can be quickly retrieved with (a > b) ? a : b.
Topic archived. No new replies allowed.