/* * Example: Read command-line arguments and write them into a map with string keys and int values * * To test, for example, execute "./map-example Alpha Gamma Alpha Beta" */ #include #include #include int main(int argc, char** argv) { std::map command_line_args; for(int i = 0; i < argc; i++) command_line_args[argv[i]] = i; /* * note that maps (and sets) are sorted data structures, * therefore traversal will automatically be sorted by key */ for(auto i = command_line_args.begin(); i != command_line_args.end(); i++) { /* output at what command line argument no. a given word was last observed */ std::cout << "Key: " << i->first << "\t\tValue (last occurrence): " << i->second << "\n"; } }