std::unordered_set::size
来自cppreference.com
< cpp | container | unordered set
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| size_type size() const; |
(C++11 起) | |
Returns the number of elements in the container, i.e. std::distance(begin(), end()).
目录 |
[编辑] 参数
(无)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 返回值
在容器中的元素的数量
Original:
the number of elements in the container
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 例外
[编辑] 复杂性
Constant
[编辑] 为例
The following code uses size to display the number of elements in a std::unordered_set<int>:
#include <unordered_set> #include <iostream> int main() { std::unordered_set<int> nums {1, 3, 5, 7}; std::cout << "nums contains " << nums.size() << " elements.\n"; }
Output:
nums contains 4 elements.
[编辑] 另请参阅
| 检查是否容器是空的 Original: checks whether the container is empty The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) | |
| 返回可能的最大数量的元素 Original: returns the maximum possible number of elements The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) | |