Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use map Standard template Library in C++

Shulou Source: shulou.com Published: 2022-05-31 22:18:51 10月03日 Update

This article mainly explains "how to use the map standard template library in C++", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use the map standard template library in C++.

One: introduction

Map is the relational container of STL, which is stored in the form of key-value. The red-black tree (balanced binary search tree) is used as the underlying data structure, and the data can be sorted automatically.

The namespace is std and belongs to the header file Note: no

Second, common operations

Capacity:

Data of actual data in a.map: map.size ()

The number of most big data in b.map: map.max_size ()

c. Determine whether the container is empty: map.empty ()

Modify:

a. Insert data: map.insert ()

b. Clear the map element: map.clear ()

c. Delete the specified element: map.erase (it)

Iterator:

A.map start pointer: map.begin ()

B.map tail pointer: map.end () Note: the next position of the last element, similar to NULL, is not the last element of the container

Three: storage

Map map1; / / method 1: map1.insert (pair (2, "beijing")); / / method 2: map1 [4] = "changping"; / / method 3: map1.insert (map::value_type (1, "huilongguan")); / / method 4: map1.insert (make_pair (3, "xierqi"))

Four: traversing

For (map::iterator it=map1.begin (); itinerant mapping 1.end (); it++) {cout first

Tags: Methods data elements standards templates caterpillars containers content actual pointer c storage learning practical deeper maximum location interest function utility Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MariaDB MySQL Microsoft vpn