C++ map empty() FunctionC++ map empty() function is used to check whether the map container is empty or not. It returns true, if the map container is empty (size is 0) otherwise false. SyntaxParameterNone Return valueIt returns true, if the map container is empty (size is 0) otherwise false. Example 1Let's see a simple example to check if a map contains any element or not. Output: Initially, numbers.empty(): 1 After adding elements, numbers.empty(): 0 In the above example, initially size of map is 0 hence, empty() function returns 1(true) and after adding elements it returns 0(false). Example 2Let's see a simple example to check whether map is empty or not. Output: Map is empty Map is not empty In the above example, if condition statement is used. If map is empty it will return map is empty after adding elements it will return map is not empty. Example 3Let's see a simple example. Output: x => 100 y => 200 z => 300 In the above example, It simply use the empty() function in 'while' loop and prints the elements of map until the map is not empty. Example 4Let's see a simple example. Output: Map is empty. Please insert content! Enter three sets of name and number: Nikita 555555 Nidhi 111111 Deep 333333 List of telephone numbers: Deep 333333 Nidhi 111111 Nikita 555555 In the above example, the program first creates phone map interactively with three names. Then, it checks the map is empty or not. If map is empty then it displays a message otherwise, it displays all the names and their telephone numbers available in the map. Next TopicC++ Map |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India