Does anyone know that is there a way that I can change the map order from less to kind of "more"?
For example:
There is a map<string, int>
called test
. I insert some entries to it:
test["b"] = 1;
test["a"] = 3;
test["c"] = 2;
Inside the map, the order will be (a, 3)(b, 1)(c, 2)
.
I want it to be (c, 2)(b, 1)(a, 3)
.
How can I do that in a easy way?
By using std::greater
as your key instead of std::less
.
e.g.
std::map< std::string, int, std::greater<std::string> > my_map;
See the reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With