Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
multimap.cpp
Go to the documentation of this file.
1
29#include <iostream> // for cout, ostream
30#include <map> // for multimap
31#include <string> // for string
32
33#include <examples.h>
34
35
36typedef std::multimap<int, std::string, std::less<int>,
37 std::allocator<std::pair<const int, std::string> > >
39
40
41// Print out a multimap.
42inline std::ostream&
43operator<< (std::ostream &out, const months_type &m)
44{
45 for (months_type::const_iterator it = m.begin (); it != m.end (); ++it)
46 std::cout << (*it).second << " has " << (*it).first << " days\n";
47
48 return out;
49}
50
51
52int main ()
53{
54 // Create a multimap of months and the number of days in the month.
55 months_type months;
56
57 typedef months_type::value_type value_type;
58
59 // Put the months in the multimap with the number of days
60 // as the not necessarily unique key.
61 months.insert (value_type (31, std::string ("January")));
62 months.insert (value_type (28, std::string ("Febuary")));
63 months.insert (value_type (31, std::string ("March")));
64 months.insert (value_type (30, std::string ("April")));
65 months.insert (value_type (31, std::string ("May")));
66 months.insert (value_type (30, std::string ("June")));
67 months.insert (value_type (31, std::string ("July")));
68 months.insert (value_type (31, std::string ("August")));
69 months.insert (value_type (30, std::string ("September")));
70 months.insert (value_type (31, std::string ("October")));
71 months.insert (value_type (30, std::string ("November")));
72 months.insert (value_type (31, std::string ("December")));
73
74 // Print out the months.
75 std::cout << "All months of the year\n" << months << std::endl;
76
77 // Find all months with 30 days.
78 std::pair<months_type::iterator, months_type::iterator> p =
79 months.equal_range (30);
80
81 // Print out the 30 day months.
82 std::cout << "\nMonths with 30 days\n";
83
84 for ( ; p.first != p.second; ++p.first)
85 std::cout << (*p.first).second << '\n';
86
87 return 0;
88}
#define m
Definition 17.names.cpp:129
#define p
Definition 17.names.cpp:132
const int out
std::map< std::string, int, std::less< std::string >, std::allocator< std::pair< const std::string, int > > > months_type
Definition map.cpp:39
std::ostream & operator<<(std::ostream &out, const months_type &m)
Definition multimap.cpp:43
std::multimap< int, std::string, std::less< int >, std::allocator< std::pair< const int, std::string > > > months_type
Definition multimap.cpp:38
int main()
Definition multimap.cpp:52