Dela via


vector::size

Returns the number of elements in the vector.

size_type size( ) const;

Return Value

The current length of the vector.

Example

// 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.

Requirements

Header: <vector>

Namespace: std

See Also

Reference

vector Class

vector::size and vector::capacity

Standard Template Library

Other Resources

vector Members