.the program is running .display the frequency of words and sort them from highest count to lowest.
my problem is about the duplication of the counts or value of the words.if the value of the word are same it only display the first word&value ...can some one help
here is the program
#include <iostream>
#include <map>
#include <fstream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <iterator>
#include <set>
using namespace std;
struct sortPairSecond
{
bool operator()(const pair<string, int> &lhs, const pair<string, int> &rhs)
{
return rhs.second < lhs.second;
}
};
typedef map<string,int> word_count_list;
int main()
{
word_count_list word_count;
string filename;
// Get the filename.
cout << "Enter the file you wish to have searched:\n";
cin >> filename;
// Open file.
ifstream file(filename.c_str());
// Read in all the words.
string word;
while (file >> word)
{
// Remove punctuation.
int index;
while ((index = word.find_first_of(".,!?\\;-*+")) != string::npos)
{
word.erase(index, 1);
}
++word_count[word];
}
// Print out the word counts.
set<pair<string,int>, sortPairSecond > mySet;
for(map<string, int>::const_iterator it = word_count.begin(); it != word_count.end(); ++it)
{
mySet.insert(*it);
}
cout << "\nSet Order:\n--------------\n";
for(set<pair<string, int> >::const_iterator it = mySet.begin(); it != mySet.end(); ++it)
{
cout << it->first << " = " << it->second << "\n";
}
system("pause");
}