title: Hash map to find a pair that add to a given sum
body: <p>I'm trying to learn how to use hash maps in C++ and am having trouble getting a randomly generated array into a hash map with ints for keys and vectors as the values(for repeated values in the array). I haven't gotten to coding the sum yet, as I want to make sure I can input the array into the hashmap first.</p>
  
  <p>When I output the hash map with my display function I get </p>
  
  <pre><code>        Total size: 1
   Index in H  Number
  key: 0  values: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  </code></pre>
  
  <p>The array I create has 15 values ranging from 1-10, so there are repeats, hence the need for vectors. I'm not sure what I am doing wrong, so any kind of guidance would be welcome.</p>
  
  <pre><code>#include &lt;iostream&gt;   
  #include &lt;time.h&gt;     
  #include &lt;fstream&gt;
  #include &lt;map&gt;
  #include &lt;cstdlib&gt;
  #include &lt;iomanip&gt;
  #include &lt;vector&gt;
  
  void display(std::map &lt;int, std::vector&lt;int&gt; &gt; hash);
  
  int main(){
      srand (time(NULL));
      int temp;
      int tempCount = 1;
      int count = 0;
      int number;
      int k = 10; //sum for pairs in an array
  
  //create array for testing
      int size = 15;
      int foo[size] = {};
      for(int i = 0; i &lt; size; ++i){
          foo[i] = ((double)rand() * (10 - 1) / (double)RAND_MAX + 1);
      }
      //print array:
          for(int i = 0; i &lt; size; ++i){
          std::cout &lt;&lt; foo[i] &lt;&lt; std::endl;
      }
  
  //Find pairs in an array whose sum is equal to ten using hash map    
      std::map &lt;int, std::vector&lt;int&gt; &gt; hash;
      const std::pair&lt;int, int&gt; pairs[size];
      for(int i = 0; i &lt; size; i++){
          std::make_pair(pairs[foo[i]] , i);
      }
  
      const int N = sizeof(pairs) / sizeof(pairs[0]);
      for(int i = 0; i &lt; N; ++i){
          const int&amp; key = pairs[i].first;
          const int value = pairs[i].second;
          hash[key].push_back(value);
      }
      display(hash);
  }
  
  void display (std::map &lt;int, std::vector&lt;int&gt; &gt; hash)
  {
      std::cout &lt;&lt; "\tTotal size: " &lt;&lt; hash.size() &lt;&lt; std::endl; /* Output the size */
      /* Create an iterator, much like vector iterators */
      std::map &lt;int, std::vector&lt;int&gt; &gt;::iterator it;
      for (it = hash.begin(); it != hash.end(); it++){
          /* Output first (which is index) and second (which is the element) */
  
          const int&amp; key = it-&gt;first ;
          std::cout &lt;&lt; "key: " &lt;&lt; key &lt;&lt; "  values: ";
  
          const std::vector&lt;int&gt;&amp; values = it-&gt;second ;
          for(std::size_t i = 0; i &lt; values.size(); ++i)
              std::cout &lt;&lt; values[i] &lt;&lt; ' ';
          std::cout &lt;&lt; '\n';
      }
  
      std::cout &lt;&lt; std::endl; /* Print a new line */
  }
  </code></pre>