-
Trouble sorting a list
Code:
#include <iostream>
#include <algorithm>
#include <fstream>
#include <iterator>
#include <string>
#include <vector>
#include <list>
bool strLesser(const std::string &elem1, const std::string &elem2) const
{
return elem2.size() > elem1.size();
}
int main()
{
std::list<std::string> WordList;
WordList.push_back("Hello");
WordList.push_back("This");
WordList.push_back("is");
WordList.push_back("Just");
WordList.push_back("Hello");
WordList.push_back("a");
WordList.push_back("Test");
WordList.push_back("a");
// Alphabetical sort first
WordList.sort();
// Remove duplicates
WordList.unique();
// Character count sort
std::stable_sort(WordList.begin(), WordList.end(), strLesser);
return 0;
}
When I ran the above code I got this error message 3 times.
Code:
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(1591): error C2064: term does not evaluate to a function taking 2 arguments
I even tried using sort instead of stable_sort but I got even more error messages. I can't figure out where that error is coming from; when I clicked on it it took me to the sort generic algorithm so that didn't help there. Thanks for the help.
My mistake, when I posted this earlier I mistyped the the wordlist as vector. Anyways, I get the errors above with a list still.
-
hmm... strLesser() shouldnt be const since it isnt a member function.
I dont think std::vector has sort() and unique() member functions.