public member function

std::map::size

<map>
size_type size() const;
Return container size
Returns the number of elements in the container.

Parameters

none

Return Value

The number of elements that conform the map's content.

Member type size_type is an unsigned integral type.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// map::size
#include <iostream>
#include <map>
using namespace std;

int main ()
{
  map<char,int> mymap;
  mymap['a']=101;
  mymap['b']=202;
  mymap['c']=302;

  cout << "mymap.size() is " << (int) mymap.size() << endl;

  return 0;
}


Output:
mymap.size() is 3

Complexity

Constant.

See also