Help reversing the order of the output

I need help reversing the order of the output from the this code. The code gets a list from a .txt file of food brands then out puts how many instances the brand occurres. I need it to be in descending order not ascnding tho, an dthat where I'm stuck.

The text file is similar to.
Westminster Cracker Company
Warburtons
Hovis
Westminster Cracker Company
Nabisco
McVitie's
Mother's Pride
McVitie's
Pepperidge Farm
Westminster Cracker Company




Heres the main file.


#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <windows.h>
#include <algorithm>
#include <map>


using namespace std;


int main()
{
SetConsoleTitle( TEXT( "Blah blah Lucien Minot" ) );//window title

//Varibles

string carName; //stores the car name
const int carNumber = 7;
string brand[carNumber]; //array to store the number of car entries

ifstream inFile;


inFile.open("foodBrands.txt");
if ( !inFile )
{
cout << "Error in opening file\n"; //check on file loading
return 0;
}
// read and display the file's contents
cout << "********** food Brand Totals **********" << endl << endl;

map<string,int> stringCounts; //searches the array for the occerrence of brand names
map<string,int>::iterator iter;



while(getline(inFile, carName)) stringCounts[carName]++;


for( iter = stringCounts.begin(); iter != stringCounts.end(); iter++ ) {
cout << "Brand: " << iter->first << ", Occurrences: " << iter->second << endl;
}


inFile.close();

return 0;

}
use rbegin() and rend() (reverse iterators)

?
Topic archived. No new replies allowed.