how to sort the value stored in pair

I would like to sort the value that stored in a pair, in descending order(from highest to the lowest). The pair I have defined looks like :

pair<string, double> temp1;

where double stores the frequency of occurrence of the string.

I want to write only top 3 frequencies into a file?

can anybody help?
Last edited on
Just use a vector of pairs, then sort it normally. Then you can just grab the top three out of it.
how to use the vectors of pairs ? sorry I am not very good in c++!!
How are you storing your pairs?
@kbw
I am sorry i did not get your question
I take it you have quite a few pairs. Are they being held in an array, in named variables, an STL container, something else?

Why? If they're being held in an STL container, you could define a Less that defines the sort order.
Topic archived. No new replies allowed.