How to use map Dictionary in C++
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