名稱空間
變體
操作

std::map<Key,T,Compare,Allocator>::size

來自 cppreference.com
< cpp‎ | 容器‎ | map
 
 
 
 
size_type size() const;
(C++11 起無異常丟擲)

返回容器中的元素數量,即 std::distance(begin(), end())

目錄

[編輯] 返回值

容器中的元素數量。

[編輯] 複雜度

常數時間。

[編輯] 示例

#include <cassert>
#include <map>
 
int main()
{
    std::map<int, char> nums{{1, 'a'}, {1, 'b'}, {2, 'c'}, {2, 'd'}};
    assert(nums.size() == 2); 
}

[編輯] 另請參閱

檢查容器是否為空
(公共成員函式) [編輯]
返回元素的最大可能數量
(公共成員函式) [編輯]
(C++17)(C++20)
返回容器或陣列的大小
(函式模板) [編輯]