Your Python code actually translates to C++ pretty much directly:
# Python:
# Create a dictionary mapping strings to functions
methods = { "foo" : foo, "bar" : bar }
// C++:
// create a map, mapping strings to functions (function pointers, specifically)
std::map<std::string, void(*)()> methods;
methods["foo"] = foo;
methods["bar"] = bar;
# Python
choice = input("foo or bar? ")
// C++:
std::string choice;
std::cout << "foo or bar? ";
std::cin >> choice;
# Python:
methods[choice]()
// C++
methods[choice]();
Python's dictionary is similar to C++'s map
. They're both associative containers, mapping a value from one type to a value of another (in our case, string to function).
In C++, functions aren't quite first-class citizens, so you can't store a function in a map, but you can store a pointer to a function. Hence the map definition gets a bit hairy, because we have to specify that the value type is a "pointer to a function which takes no arguments and returns void".
On a side note, it is assumed that all your functions have the same signature. We can't store both functions that return void and functions that return an int in the same map without some additional trickery.