diff --git a/client/src/pages/guide/english/cplusplus/map/index.md b/client/src/pages/guide/english/cplusplus/map/index.md index 14772b23bf..41e8d36146 100644 --- a/client/src/pages/guide/english/cplusplus/map/index.md +++ b/client/src/pages/guide/english/cplusplus/map/index.md @@ -50,6 +50,19 @@ d => 40 ## Creating map object ` map myMap; ` +## Get Size +Get size of map with size function +``` +map myMap; +myMap[100] = 3 +count << "size of map is " << myMap.size() << '\n'; +``` + +Output: +``` +size of map is 1 +``` + ## Insertion Inserting data with insert member function. @@ -62,6 +75,42 @@ We can also insert data in std::map using operator [] i.e. `myMap["sun"] = 3;` +If "sun" is already mapped before, this action will override the value mapped to key. + +## Erase +Erasing data with erase function + +``` +map myMap; +myMap[10] = 1000; +cout << "before erase, size of map is " << myMap.size() << '\n'; +myMap.erase(10); +cout << "after erase, size of map is " << myMap.size() << '\n'; +``` + +Output: +``` +before erase, size of map is 1 +after erase, size of map is 0 +``` + +## Accessing map value + +To access map values, simply call Map[key]. For example: +``` +map M; +M["abc"] = 1; +M["def"] = 2; +cout << "value of abc is " << M["abc"] << '\n'; +cout << "value of def is " << M["def"] << '\n'; +``` + +Output: +``` +value of abc is 1 +value of def is 2 +``` + ## Accessing map elements To access map elements, you have to create iterator for it. Here is an example as stated before.