Hi, all
its me again!
Still stuck with the STL function usage.
but this time face the sort function problems!
here is my class:

class A
    A( const string& filename )
       ifstream file(filename.c_str()) ;
        string word;
       while( file >> word)
    StringIntVector topNWords(size_t n) const;
     bool isnotpuct() const;
    // this function is to judge weather the text inside the file
    // is punctuations.
    vector<string> _word_list;


My topnwords function implementation-- this function is used for return find the top n times words occurrence

//stringvector is the type--
//typedef vector< pair < string, int > > StringIntVector;

StringIntVector TextUtil::topNWords(size_t n) const
    map<string, int> freq;
   StringIntVector vRet;
    for(size_t i=0; i<_word_list.size(); i++)
      string words = _word_list[i];
      size_t topn = wordCount(words);
      freq[words] = topn;
    map<string, int>::const_iterator iter;
    for (iter=freq.begin(); iter != freq.end(); iter++)
      return vRet;

But this one got bunch of errors on vc++. The error always point me to the algorithm file which i could not understand.

Error	2	error C2784: 'reverse_iterator<_RanIt>::difference_type std::operator -(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::_Tree<_Traits>::iterator'

Seems like my sort function usage is wrong. But how i could change my code to use it??
Many thanks.

7 Years
Discussion Span
Last Post by Narue

The translation of your error is that std::map doesn't support random access iterators, and random access iterators are required for std::sort to work. However, std::map is already sorted on the key, so there's no need to explicitly sort anyway.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.