![]() |
In C++, maps are used to store key-value pairs in which each key is unique. In this article, we will learn how to delete a key-value pair from a map in C++. Example Input: Remove a Key-Value Pair from Map in C++To delete a key-value pair from a map, we can use the std::map::erase() method. First, we will check if a key for a key-value pair that you want to delete exists or not. If it exists, we then remove it by simply passing the key to the erase() function. C++ Program to Delete Key-Value Pair from MapC++
Output
Map before deletion: 1: One 2: Two 3: Three Map after deletion: 1: One 3: Three Time Complexity: O(log N)
|
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |