How to Find the Size of a Map in C++? Last Updated : 21 Feb, 2024 Comments Improve Suggest changes Like Article Like Report In C++ STL, maps are associative containers that store elements in a mapped fashion. Each element has a key value and a mapped value. No two mapped values can have the same key values. In this article, we will learn how to find the size of a map in C++ STL. Example: Input: myMap = { {1, "Sravan"}, {2, "Bobby"}, {3, "Srijay"}, {4, "Riya"} } Output: Size of map: 4Find the Size of a Map in C++In C++, you can find the size of a map using the std::map::size() member function of the std::map container. This function returns the number of key-value pairs stored in the map. C++ Program to Find the Size of a Map C++ // C++ program to find the size of the map #include <iostream> #include <map> using namespace std; int main() { // Create map - students_data map<int, string> students_data; // Insert 10 values into the above map students_data.insert(make_pair(1, "Sravan")); students_data.insert(make_pair(2, "Bobby")); students_data.insert(make_pair(3, "Siva Nagulu")); students_data.insert(make_pair(4, "Bhavanarayana")); students_data.insert(make_pair(5, "Ojaswi")); students_data.insert(make_pair(6, "Gnanesh")); students_data.insert(make_pair(7, "Sireesha")); students_data.insert(make_pair(8, "Priyank Chowdhary")); students_data.insert(make_pair(9, "Rohith")); students_data.insert(make_pair(10, "Ravi Kumar")); // Display the map size using the map::size() function. cout << "Total Students: " << students_data.size(); cout << endl; return 0; } OutputTotal Students: 10 Time Complexity: O(1)Space Complexity: O(1) Time complexity: O(n)Auxiliary Space: O(n) Comment More infoAdvertise with us Next Article How to Find the Size of a Map in C++? G gottumukkala_sivanagulu Follow Improve Article Tags : C++ Programs C++ STL cpp-map CPP Examples +1 More Practice Tags : CPPSTL Similar Reads How to Find the Size of a List in C++? In C++, Standard Template Library (STL) we have a std::list container that is a doubly-linked list in which elements are stored in non-contiguous memory allocation. In this article, we will learn how to find the size of a list in C++ STL. Example: Input: myList = {10, 20, 30, 40, 50}; Output: Size o 2 min read How to Find the Size of a Map in Bytes in C++? In C++, maps are associative containers that store a key value and a mapped value for each element and no two mapped values can have the same key values. In this article, we will explore how to find the size of the map in bytes in C++. Example Input: myMap = {{âappleâ, 1}, {âbananaâ, 2}, {âcherryâ, 2 min read How to Find the Size of a Set in C++? In C++, sets are STL containers that store unique elements of the same type in a sorted manner. No duplicate elements are allowed in the sets, as the value of every element in a set is unique. In this article, we will learn how we can find the size of a set container in C++. Example: Input: mySet={1 2 min read How to Find the Size of a Vector in C++? The size of a vector means the number of elements currently stored in the vector container. In this article, we will learn how to find the size of vector in C++.The easiest way to find the size of vector is by using vector size() function. Letâs take a look at a simple example:C++#include <bits/s 2 min read How to Find the Size of a Set in Bytes in C++? In C++, sets are associative containers that only store unique elements. The elements inside the set are sorted in a specific order. In this article, we will learn how we can find the size of a set in bytes in C++. Example Input: S = {1,2,3,4}Output: Size of the set in bytes is : 16Find the Size of 2 min read Like