Len,
std::list::sort() requires your contained type to have a less-than operator (<) defined. So you need to write the following just before your main function (I haven't tested this so I hope it works):
boolean operator<(
const fnameStruct& left,
const fnameStruct& right)
{
return left.fname < right.fname;
}
I hope that works.
If you like, I can offer you a few more suggestions about your code. (Most of the advice below can be fully researched in a good book like Scott Meyers' Effective C++.)
#include <utility>
What's that for? You don't seem to be using <utility>.
typedef struct sFname_tag
{
...
} fnameStruct;
You can simply do
struct fnameStruct
{
...
};
(or struct FnameStruct as it's conventional to capitalize struct and class names.)
typedef std::list<fnameStruct> LISTSTRUCT;
Most experienced C++ programmers recommend using all-capitals only for the preprocessor. So the above would conventionally be called ListStruct.
LISTSTRUCT::iterator i;
It's recommended declaring variable at the point of first use. In this case, that would be inside the parenthesis after the for statement.
for (i = listStruct.begin(); i != listStruct.end(); ++i)
{
fnameS = *i;
...
}
This performs an unnecessary copy of the whole stucture. This would have been expensive if your structure was much larger. You can avoid the copy by using a reference:
for (i = listStruct.begin(); i != listStruct.end(); ++i)
{
const FnameStruct & fnameS = *i;
...
}
listStruct.sort();
Once you've declared your less-than operator, this should work.
Finally, looking at your code again, I was wondering if a list is really what you need. Are you creating a lookup table of names and attributes? Then perhaps std::map(string, char) would be more suitable, and then you can get rid of the structure, and you won't have to worry about sorting.