title: STL Unordered Map- inserting into a vector
body: <p>I am not too familiar with the STL's unordered map and I'm having trouble inserting elements into it. </p>
  
  <p>So I have an unordered map where the key is a string and the mapped value is a vector of integers. I have it declared as:</p>
  
  <pre><code>              unordered_map&lt;string, vector&lt;int&gt; &gt; categorySearch;
  </code></pre>
  
  <p>How would I go about inserting elements into this map. I am currently doing</p>
  
  <pre><code>       categorySearch.insert(make_pair("hello", categorySearch["hello"].push_back(5)));
  </code></pre>
  
  <p>This is clearly giving me compiler errors. How do I use insert for the vector portion of the map. </p>
  
  <p>Here is the compiler error I am getting:</p>
  
  <pre><code>logData.h: In member function ‘void LogData::addEntry(Log)’:
  logData.h:23:68: error: no match for ‘operator[]’ (operand types are ‘std::unordered_map&lt;std::basic_string&lt;char&gt;, std::vector&lt;int&gt; &gt;’ and ‘&lt;unresolved overloaded function type&gt;’)
  categorySearch.insert(make_pair(add.getCategory(), categorySearch[add.getCategory].push_back(data.size()-1)));
                                                                  ^
  logData.h:23:68: note: candidates are:
  In file included from /usr/um/gcc-4.8.2/include/c++/4.8.2/unordered_map:48:0,
               from logData.h:2,
               from logman.cpp:5:
  /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/unordered_map.h:595:7: note: std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::mapped_type&amp; std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::operator[](const key_type&amp;) [with _Key = std::basic_string&lt;char&gt;; _Tp = std::vector&lt;int&gt;; _Hash = std::hash&lt;std::basic_string&lt;char&gt; &gt;; _Pred = std::equal_to&lt;std::basic_string&lt;char&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const std::basic_string&lt;char&gt;, std::vector&lt;int&gt; &gt; &gt;; std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::mapped_type = std::vector&lt;int&gt;; std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::key_type = std::basic_string&lt;char&gt;]
     operator[](const key_type&amp; __k)
     ^
  /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/unordered_map.h:595:7: note:   no known conversion for argument 1 from ‘&lt;unresolved overloaded function type&gt;’ to ‘const key_type&amp; {aka const std::basic_string&lt;char&gt;&amp;}’
  /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/unordered_map.h:599:7: note: std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::mapped_type&amp; std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::operator[](std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::key_type&amp;&amp;) [with _Key = std::basic_string&lt;char&gt;; _Tp = std::vector&lt;int&gt;; _Hash = std::hash&lt;std::basic_string&lt;char&gt; &gt;; _Pred = std::equal_to&lt;std::basic_string&lt;char&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const std::basic_string&lt;char&gt;, std::vector&lt;int&gt; &gt; &gt;; std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::mapped_type = std::vector&lt;int&gt;; std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::key_type = std::basic_string&lt;char&gt;]
     operator[](key_type&amp;&amp; __k)
     ^
  /usr/um/gcc-4.8.2/include/c++/4.8.2/bits/unordered_map.h:599:7: note:   no known conversion for argument 1 from ‘&lt;unresolved overloaded function type&gt;’ to ‘std::unordered_map&lt;std::basic_string&lt;char&gt;, std::vector&lt;int&gt; &gt;::key_type&amp;&amp; {aka std::basic_string&lt;char&gt;&amp;&amp;}’
  make: *** [logman.o] Error 1
  </code></pre>
  
  <p>Thanks.</p>