Home › C++ Tutorial › C++ maps
C++ maps
Key-value pairs.
A map stores sorted key-value pairs. Access with [], search with find.
Commands in this lesson
map
Definition: Builds a new array by transforming each item.
Syntax:
array.map(function);
Example:
console.log([1, 2, 3].map(function(x){ return x * 2; }));Example code
#include <iostream>
#include <map>
using namespace std;
int main() {
map<string, int> age = {{"Ravi", 30}};
age["Ada"] = 36;
for (auto &p : age) cout << p.first << "=" << p.second << " ";
cout << endl;
return 0;
}