Map Syntax

Map Literal Syntax:

map<string, string> id2name = {
	{"235", "Data Structures"},
	{"142", "Intro to Programming"},
	{"236", "Discrete Stuff"}
};

Access items

cout << id2name["235"] << endl;
console: Data Structures

Unlike Python, this will not throw an error:

cout << id2name["110"] << endl;
console:

This will add a value of 110 to the map.

However, using the .get(my_key) function will raise errors if it does not exist.

Like this

id2name.get("111")
console: error

Use this to see if a key is in a map.

id2name.find("142") != id2name.end()