Source of map03.cpp


  1: //map03.cpp

  3: #include <iostream>
  4: #include <iomanip>
  5: #include <map>
  6: using namespace std;

  8: int main()
  9: {
 10:     cout << "\nThis program illustrates the member function max_size() "
 11:         "and shows how the\nmaximum size of a map depends on its "
 12:         "component type.";
 13:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 15:     cout << "\nHere are the maximum sizes of several maps "
 16:         "of different component types:\n\n";

 18:     map<int, int> m1;
 19:     map<int, double> m2;
 20:     map<int, char> m3;
 21:     map<string, double> m4;

 23:     //Just something that takes up a lot of space
 24:     struct BigThing
 25:     {
 26:         double first[10000];
 27:         double second[1000000];
 28:     };
 29:     map<string, BigThing> m5;

 31:     cout << "Maximum size of a map<int, int> .........."
 32:         << setw(11) << m1.max_size() << "\n"

 34:         << "Maximum size of a map<int, double> ......."
 35:         << setw(11) << m2.max_size() << "\n"

 37:         << "Maximum size of a map<int, char> ........."
 38:         << setw(11) << m3.max_size() << "\n"

 40:         << "Maximum size of a map<string, double> ...."
 41:         << setw(11) << m4.max_size() << "\n"

 43:         << "Maximum size of a map<string, BigThing> .."
 44:         << setw(11) << m5.max_size() << "\n\n";

 46:     cout << "Press Enter to continue ... ";  cin.ignore(80, '\n');
 47: }