title: How to create a keyboard listener from map?
body: <p>I got a task to create a map with key values and functions inside. I managed to do that. Now I need to create a loop where I need to call a different print function by pressing up, down, left, right keyboard buttons(eg, i press up, the function prints "UP"). Any idea how? My mentor told me that its a practice for understanding the usage of function object. Here is my program for now:</p>
  
  <pre><code>#include &lt;functional&gt;
  #include &lt;iostream&gt;
  #include &lt;string.h&gt;
  #include &lt;map&gt;
  
  
  
  using namespace std;
  
  
  void up (){
  
      cout&lt;&lt;"UP";
  }
  
  void down (){
  
      cout&lt;&lt;"DOWN";
  }
  
  void left (){
  
      cout&lt;&lt;"LEFT";
  }
  void right (){
  
      cout&lt;&lt;"RIGHT";
  }
  
  
  int main (){
  
     typedef map&lt;int, void (*)()&gt; mapaF;
  
      mapaF Kretnje;
  
      Kretnje.insert(pair&lt;int,void (*)() &gt;(1, up));
      Kretnje.insert(pair&lt;int, void (*)()&gt;(2, down));
      Kretnje.insert(pair&lt;int, void (*)()&gt;(3, left));
      Kretnje.insert(pair&lt;int, void (*)()&gt;(4, right));
  
      for(auto a: Kretnje){
          cout&lt;&lt;"Kljuc: "&lt;&lt;a.first&lt;&lt;" Funkcija: ";
           a.second();
           cout&lt;&lt;endl;
  
      }
  
  
  
  
      return 0;
  }
  </code></pre>