Skip to content

Instantly share code, notes, and snippets.

@AndyNovo
Created September 16, 2016 15:42
Show Gist options
  • Select an option

  • Save AndyNovo/a1037cdd88afa87d336196f4ddc8d50d to your computer and use it in GitHub Desktop.

Select an option

Save AndyNovo/a1037cdd88afa87d336196f4ddc8d50d to your computer and use it in GitHub Desktop.
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main()
{
/* type of the container:
* - map: elements key/value pairs
* - string: keys have type string
* - float: values have type float
*/
typedef map<string,float> StringFloatMap;
StringFloatMap coll;
// insert some elements into the collection
coll["VAT"] = 0.15;
coll["Pi"] = 3.1415;
coll["an arbitrary number"] = 4983.223;
coll["Null"] = 0;
/* print all elements
* - iterate over all elements
* - element member first is the key
* - element member second is the value
*/
StringFloatMap::iterator pos;
for (pos = coll.begin(); pos != coll.end(); ++pos) {
cout << "key: \"" << pos->first << "\" "
<< "value: " << pos->second << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment