C++ STL vector, max_size() code example

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C++

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)

Other info: none

To do: Using the C++ max_size() to return the maximum length of the vector in C++ programming

To show: How to use the C++ vector, max_size() to return the maximum length of the vector in C++ programming

 

// C++ STL vector, max_size()

#include <vector>

#include <iostream>

using namespace std;

 

int main(void)

{

vector <int> vec1;

vector <int>::size_type i;

 

i = vec1.max_size();

cout<<"The max possible length of the vec1 vector is "<<i<<endl;

return 0;

}

 

Output examples:

 

The max possible length of the vec1 vector is 1073741823

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index