Yurttas/PL/OOL/Cplusplus/F/07/03/01/mmap 02.cpp

 1/*
 2   Copyright(C) 2000
 3   All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
 4
 5   Permission to use, copy, modify, and distribute this
 6   software and its documentation for EDUCATIONAL purposes
 7   and without fee is hereby granted provided that this
 8   copyright notice appears in all copies.
 9
10   date   : January 1, 2000.
11   authorĀ : Salih Yurttas.
12
13   mmap_01.cpp
14*/
15
16
17#include <iostream>
18
19#include <vector>
20#include <string>
21
22#include <map>
23
24using namespace std;
25
26int main(int argc, char* argv[]) {
27
28    string fruits[] = {"strawberry",
29                       "plum",
30                       "apple",
31                       "orange",
32                       "apricot",
33                       "peach",
34                       "mango",
35                       "watermelon"};
36
37    vector<string> fruits_list(fruits, fruits+8);
38
39    int counts[] = {4,
40                    4,
41                    1,
42                    8,
43                    1,
44                    1,
45                    7,
46                    3};
47
48    vector<int> counts_list(counts, counts+8);
49
50    multimap<string, int, less<string> > counts_fruits_list;
51
52    int n = counts_list.size();
53    for(int i=0; i<n; ++i)
54      counts_fruits_list.insert(pair<string,int>(fruits_list.at(i),counts_list.at(i)));
55
56    multimap<string, int, less<string> >::const_iterator i = counts_fruits_list.begin();
57    multimap<string, int, less<string> >::const_iterator k = counts_fruits_list.end();
58
59    for(; i!=k; ++i)
60      cout << i->first << " - " << i->second << endl;
61
62}