Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

(C++) std::map

 

STL container for mapping two kinds of data types.

 

 

#include <map>

 

std::map<std::string, int> phonebook;

 

 

The std::string is the key (in this case a last name) and the int is termed the value (in this calse the persons telephone number).

 

One key can only have one value. If a key needs to have one or more values, use a std::multimap.

 

std::map code snippets

 

Note that among these are also more general container code snippets.

 

*       IsKeyInMap, checks if a key is in a std::map

*       GetValueInMap, get a value in a std::map

*       Check if a key is in a std::map, IsKeyInMap

*       Get a value in a std::map, GetValueInMap

*       LoopReader, reading a container looped

*       Reading a container looped, LoopReader

 

std::map compile errors

 

*       'operator+' not implemented in type 'std::map<int,double>' for arguments of type 'int'

 

External links

* Wikipedia: http://en.wikipedia.org/wiki/Map_(computer_science)

* SGI: http://www.sgi.com/tech/stl/Map.html

* CodePedia: http://www.codepedia.com/1/CppMap

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.