A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/stack/stack/size/ below:

public member function

<stack>

std::stack::size

Return size

Returns the number of elements in the stack.

This member function effectively calls member size of the underlying container object.



Parameters none

Return Value The number of elements in the underlying container.

Member type size_type is an unsigned integral type.



Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// stack::size
#include <iostream>       // std::cout
#include <stack>          // std::stack

int main ()
{
  std::stack<int> myints;
  std::cout << "0. size: " << myints.size() << '\n';

  for (int i=0; i<5; i++) myints.push(i);
  std::cout << "1. size: " << myints.size() << '\n';

  myints.pop();
  std::cout << "2. size: " << myints.size() << '\n';

  return 0;
}

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


Complexity Constant (calling size on the underlying container).

Data races The container is accessed.

Exception safety Provides the same level of guarantees as the operation performed on the container (no-throw guarantee for standard container types).

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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4