A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/cpp_standard_library/cpp_map_clear.htm below:

C++ Map Clear Function

C++ Map Library - clear() Function Description

The C++ function std::map::clear() destroys the map by removing all elements and sets size of map to zero.

Declaration

Following is the declaration for std::map::clear() function form std::map header.

C++98
void clear();
C+11
void clear() noexcept;
Parameters

None

Return value

None

Exceptions

This member function never throws exception.

Time complexity

Linear i.e. O(n)

Example

The 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