Export (0) Print
Expand All

stack::size

Returns the number of elements in the stack.

size_type size( ) const;

The current length of the stack.

// stack_size.cpp
// compile with: /EHsc
#include <stack>
#include <iostream>

int main( )
{
   using namespace std;
   stack <int> s1, s2;
   stack <int>::size_type i;

   s1.push( 1 );
   i = s1.size( );
   cout << "The stack length is " << i << "." << endl;

   s1.push( 2 );
   i = s1.size( );
   cout << "The stack length is now " << i << "." << endl;
}
The stack length is 1.
The stack length is now 2.

Header: <stack>

Namespace: std

Show:
© 2014 Microsoft