如何使用地图的指针获取地图的大小

how to get the size of the map using the pointer of the map?

本文关键字:地图 获取 指针 何使用      更新时间:2023-10-16

我有一个问题,如何使用指向地图的指针来获取地图的大小:

map<int, string> mapList;
map<int, string>* getMapList()
{
   return &mapList;
}
void main()
{
   map<int, string>* mapPointer = getMapList();
} 

那么如何使用这个pointer来获取map的大小呢?

在指针上调用size函数

mapPointer->size()
mapPointer->size()

会给你尺寸。