public member function
<queue>

std::queue::size

size_type size() const;
Return size
Returns the number of elements in the queue.

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

参数



返回值

The number of elements in the underlying container.

Member type size_type is an unsigned integral type.

示例

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

int main ()
{
  std::queue<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;
}

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


复杂度

Constant (calling size on the underlying container).

数据竞争

访问容器。

异常安全

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

另见