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