The C++ function std::map::clear() destroys the map by removing all elements and sets size of map to zero.
DeclarationFollowing is the declaration for std::map::clear() function form std::map header.
C++98void clear();C+11
void clear() noexcept;Parameters
None
Return valueNone
ExceptionsThis member function never throws exception.
Time complexityLinear i.e. O(n)
ExampleThe following example shows the usage of std::map::clear() function.
#include <iostream> #include <map> using namespace std; int main(void) { /* Initializer_list constructor */ map<char, int> m = { {'a', 1}, {'b', 2}, {'c', 3}, {'d', 4}, {'e', 5}, }; cout << "Initial size of map = " << m.size() << endl; m.clear(); cout << "Size of map after clear opearation = " << m.size() << endl; return 0; }
Let us compile and run the above program, this will produce the following result −
Initial size of map = 5 Size of map after clear opearation = 0
map.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4