Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting a list

Status
Not open for further replies.

sheila11

Programmer
Dec 27, 2000
251
0
0
US
I am trying to use List from STL for the first time. I need to create a lost of stucts.

If I create a list of strings and use the sort method, the list items get arranged as per their values. What will happen if I use sort on a list made up of structs having multiple data items, of various types?

TIA,
Sheila
 
You need to add a comparison opperator to the struct

struct myStruct
{
int data;
char buffer[128];
int operator < (myStruct ms){
return ms.data<data;
}
}

do the same for all other comparison opperations.

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top