How to initialize an Int from a map Value, C++ : <p>I have a large global map in a header of weapon names and ID numbers from a video game . I am trying to find a way that I can take user input for the name and return the item number. For this I created a new int and would like to initialize it with the map value after searching for the name. What is the best way to do this?</p>

<pre><code>//header
#include &lt;map&gt;
#include &lt;string&gt;

using namespace std;
typedef std:: map &lt;std :: string, int&gt; weaponMap;

inline
weaponMap &amp; globalMap() {
    static weaponMap theMap;
    static bool firstTime = true;
    if (firstTime) {
    firstTime = false;
      theMap["weaponOne"] = 854000;

    }
}


//Source.cpp

#includes "globalMap"

int swapWeapon = weaponMap::["weaponOne"];
    cout &lt;&lt; swapWeapon;
</code></pre>
