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 }
|