Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use map Dictionary in C++

Shulou Source: shulou.com Published: 2022-06-03 13:45:40 11月14日 Update

This article mainly introduces how to use the map dictionary in C++, it has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.

1. Declaration of map type

If you want to create a dictionary using the map type in C++, you need to include the map header file, as follows:

# include

The definition of the map type is as follows:

Map dict

Where KeyType represents the data type of the key and ValueType represents the data type of the value. KeyType defaults to type const, that is, the key is read-only data after confirmation. In addition, in a map data, a key can appear only once, while in multimap type data, a key can occur multiple times, this time mainly discusses map data. Look at the following example:

# include # include # include using namespace std;int main (void) {map dict {{"key1", 2}}; / / define a map type data dict ["key2"] = 3; / / create and assign dict ["key3"]; cout

Tags: Elements data types iterations points members methods dictionaries examples subscripts functions methods articles results ranges runs Clearing creation loops sorting Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS MariaDB Microsoft vpn Huawei