Created
September 16, 2016 15:42
-
-
Save AndyNovo/a1037cdd88afa87d336196f4ddc8d50d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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