Export (0) Print
Expand All

vector::size

Returns the number of elements in the vector.

size_type size( ) const;

The current length of the vector.

// vector_size.cpp
// compile with: /EHsc
#include <vector>
#include <iostream>

int main( )
{
   using namespace std;   
   vector <int> v1;
   vector <int>::size_type i;
   
   v1.push_back( 1 );
   i = v1.size( );
   cout << "Vector length is " << i << "." << endl;

   v1.push_back( 2 );
   i = v1.size( );
   cout << "Vector length is now " << i << "." << endl;
}
Vector length is 1.
Vector length is now 2.

Header: <vector>

Namespace: std

Show:
© 2014 Microsoft