VOOZH about

URL: https://www.geeksforgeeks.org/cpp/mapsize-c-stl/

⇱ map::size() in C++ STL - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

map::size() in C++ STL

Last Updated : 25 Oct, 2024

In C++, the std::map::size() is a built-in method used to find the number of elements in std::map container. It is the member function of std::map defined inside <map> header fie. In this article, we will learn about std::map::size() method in C++.

Example:


Output
3

map::size() Syntax

m.size()

Parameters

  • This function does not take any parameter.

Return Value

  • Returns the number of elements in the map.
  • If the map is empty, returns 0.

More Examples of map::size()

The following examples demonstrates the use of map::size() function in different scenarios:

Example 1: Checking the Size of an Empty Map


Output
0

Example 2: Size of Map after Erasing Elements


Output
3: GeeksforGeeks


Comment
Article Tags:
Article Tags: