Hello daniweb. Seems like this site is amongst the latest and the greatest in programming and software development.

Anyways:

Attempt to compile with gcc: C:\>gcc -o ywordf ywordf.cpp

Error:
ywordf.cpp: In function `int main(int, char**)':
ywordf.cpp:30: error: no match for 'operator!=' in 'i != __gnu_norm::multimap<_Key, _Tp, _Compare, _Alloc>::rend() [with _Key = size_t, _Tp = std::string, _Compare = std::less<size_t>, _Alloc = std::allocator<std::pair<const size_t, std::string> >]()'

Code:

#include <set>
#include <map>
#include <fstream>
#include <iostream>
#include <iterator>
#include <utility>

using namespace std;

int main(int ac, char** av)
{
if(ac != 2)
{
cout << "Usage: " << av[0] << " filename" << endl;
return 1;
}
cout << "Reading file " << av[1] << endl;
ifstream f(av[1]);

// read and count words
istream_iterator<string> i(f);
multiset<string> s(i, istream_iterator<string>());

// sort by count
multimap<size_t, string> wordstats;
for(multiset<string>::const_iterator i = s.begin(); i != s.end(); i = s.upper_bound(*i))
wordstats.insert( make_pair( s.count(*i), *i ));

// output in decreasing order
for( multimap<size_t, string>::const_reverse_iterator i = wordstats.rbegin(); i != wordstats.rend(); ++i)
cout << " word " << i->second << " found " << i->first << " times " << endl;
}

The error is in line 28, which is:

for( multimap<size_t, string>::const_reverse_iterator i = wordstats.rbegin(); i != wordstats.rend(); ++i)

'

What on earth am I doing wrong? What do I need to change in this line?

I've never seen this error before, but I believe it has something to do with having or not having a const value in the for(multimap( paramaters.

Help! and Thank You! I would be happy to post the purpose of my code, but its not necessary. People far more experienced than I can tell exactly what I'm doing.

AA.

Your code compiles fine on my machine.

g++ (GCC) 4.4.1 20090725 (Red Hat 4.4.1-2)

Dave

I can confirm that using G++ does compile the code on my machine. Apparently there was an STL issue or something wrong specific to my machine.

Thanks.

(Topic Resolved).

This article has been dead for over six months. Start a new discussion instead.