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

出自cppreference.com
< cpp‎ | container‎ | map
 
 
 
 
size_type size() const;
(C++11 起為 noexcept)
(C++26 起為 constexpr)

返回容器中的元素數。

目錄

[編輯] 返回值

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)
返回容器或數組的大小
(函數模板) [編輯]