Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.



Returns the number of elements in the map.

size_type size( ) const;

The current length of the map.


The following example demonstrates the use of the map::size member function.

// map_size.cpp
// compile with: /EHsc
#include <map>
#include <iostream>

int main()
    using namespace std;
    map<int, int> m1, m2;
    map<int, int>::size_type i;
    typedef pair<int, int> Int_Pair;

    m1.insert(Int_Pair(1, 1));
    i = m1.size();
    cout << "The map length is " << i << "." << endl;

    m1.insert(Int_Pair(2, 4));
    i = m1.size();
    cout << "The map length is now " << i << "." << endl;
The map length is 1.
The map length is now 2.


Header: <map>

Namespace: std

© 2016 Microsoft