multimap alphabetically ordering with char*

I understand multimaps are key ordered. I have no problems with ints but when I put my char arrays in they are not alphabetically ordered. I must use char array and not <string>. Is it possible to alphabetically order them with char*

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
39         int c;
 40         User *user;
 41         char nameH[200];
 42         char line[200];
 43         int ageH;
 44         double wH;
 45         double hH;
 46         //vector of pointers to Name structs
 47         vector <User *> v;
 48         multimap<char*,int> nameAge;
 49         multimap<int,char*> ageName;
 50         multimap<char*,int>::iterator iterNameAge;
 51         multimap<int,char*>::iterator iterAgeName;
 52 //------------------------------------------------------------------
 53 //Take values line by line from text file and store them into vars. 
 54 while(fgets(line,200,fp)){
 55         sscanf(line,"%s %d %lf %lf",nameH,&ageH,&wH,&hH);
 56 
 57         user = (User *) malloc(sizeof(User));
 58         //Store vars into structs.
 59         char *d = strdup(nameH);
 60         user->Name = strdup(nameH);
 61         user->Age = ageH;
 62         user->W = wH;
 63         user->H = hH;
 64         v.push_back(user);
 65         nameAge.insert(pair<char*,int>(user->Name,user->Age));
 66         ageName.insert(pair<int,char*>(user->Age,user->Name));
 67         //printf("%s %f","this is test: \n",user->W);
 68 }
 69         for(iterAgeName = ageName.begin(); iterAgeName != ageName.end(); iterAgeName++){
 70                 cout << endl << "By age as key - " << iterAgeName->second << endl;
 71         }
 72         for(iterNameAge = nameAge.begin(); iterNameAge != nameAge.end(); iterNameAge++){
 73                 cout << endl << "iterator " << iterNameAge->second << endl;
 74         }

-----------------------------TEXT FILE------------------------------------------
1 Fred 50 200.800 69.6
2 Mary 20 150.2 63.4
3 Sammy 23 150.44 54.3
4 Bob 43 43 34
5 Jason 33 33 33


-------------------------------Output------------------------------------------

By age as key - Mary

By age as key - Sammy

By age as key - Jason

By age as key - Bob

By age age as key - Fred

By name as key - 50

By name as key - 20

By name as key - 23

By name as key - 43

By name as key - 33
Last edited on
You need to provide your own comparison function for multimap.
And do not forget to manually delete all character pointers before multimap is destroyed to avoid memory leaks.
Got it. Did as you said and everything working. Thanks.
Topic archived. No new replies allowed.