std::map<Key,T,Compare,Allocator>::size - cppreference.com
来自cppreference.com
| (C++11 起为 noexcept) | ||
返回容器中的元素数,即 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); }