cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : STL Containers : stack : size
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
STL Containers
bitset
deque
list
map
multimap
multiset
priority_queue
queue
set
stack
vector
stack
comparison operators
stack::stack
member functions:
· stack::empty
· stack::pop
· stack::push
· stack::size
· stack::top

-

stack::size public member function
size_type size ( ) const;

Return size

Returns the number of elements in the stack.

This member function effectively calls the member with the same name in the underlying container object.

Parameters

none

Return Value

The number of elements that conform the stack's container content.

Member type size_type is an unsigned integral type.

Example

// stack::size
#include <iostream>
#include <stack>
using namespace std;

int main ()
{
  stack<int> myints;
  cout << "0. size: " << (int) myints.size() << endl;

  for (int i=0; i<5; i++) myints.push(i);
  cout << "1. size: " << (int) myints.size() << endl;

  myints.pop();
  cout << "2. size: " << (int) myints.size() << endl;

  return 0;
}

Output:

0. size: 0
1. size: 5
2. size: 4

Complexity

Constant.

See also

stack::empty Test whether container is empty (public member function)

Home page | Privacy policy
© cplusplus.com, 2000-2008 - All rights reserved - v2.2
Spotted an error? contact us