Source of vector03.cpp


  1: //vector03.cpp

  3: #include <iostream>
  4: #include <iomanip>
  5: #include <string>
  6: #include <vector>
  7: using namespace std;


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

 17:     cout << "\nHere are the maximum sizes of several vectors "
 18:         "of different component types:\n\n";

 20:     vector<int> v1;
 21:     vector<double> v2;
 22:     vector<bool> v3;
 23:     vector<char> v4;

 25:     //Just something that takes up a lot of space
 26:     struct BigThing
 27:     {
 28:         double first[10000];
 29:         double second[1000000];
 30:     };
 31:     vector<BigThing> v5;

 33:     cout << "Maximum size of a vector<int> ......."
 34:         << setw(11) << v1.max_size() << "\n"
 35:         << "Maximum size of a vector<double> ...."
 36:         << setw(11) << v2.max_size() << "\n"
 37:         << "Maximum size of a vector<bool> ......"
 38:         << setw(11) << v3.max_size() << "\n"
 39:         << "Maximum size of a vector<char> ......"
 40:         << setw(11) << v4.max_size() << "\n"
 41:         << "Maximum size of a vector<BigThing> .."
 42:         << setw(11) << v5.max_size() << "\n\n";
 43:     cout << "Press Enter to continue ... ";  cin.ignore(80, '\n');
 44: }