fork(1) download
  1. #include <iostream>
  2. #include <functional>
  3. #include <unordered_map>
  4. #include <string>
  5. using namespace std;
  6.  
  7. int main() {
  8. string greetings = "Hello, you filthy world!";
  9.  
  10. unordered_map<string, function<void()>> menu = {
  11. {"Foo", []{ cout << "Foo" << endl; }},
  12. {"Greet", [&]{ cout << greetings << endl; }}
  13. };
  14.  
  15. for(auto const & menu_item: menu){
  16. cout << "> " << menu_item.first << endl;
  17. }
  18.  
  19. string decision;
  20. cin >> decision;
  21. menu.at(decision)();
  22.  
  23. return 0;
  24. }
Success #stdin #stdout 0s 3472KB
stdin
Greet
stdout
> Greet
> Foo
Hello, you filthy world!