C++ reading contents from file into a map : <p>I have a file that I want to read into a map.</p>

<pre><code>file.txt
temperature 55
water_level 2
rain        10
........
</code></pre>

<p>While I am aware that I could use the C function 'sscanf' to parse the data. I would prefer to do this in C++ (I am only getting used to the language) and read it into a map (with the first column as the keys and 2nd as the values).</p>

<p>I have attempted it as follows:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;sstream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;map&gt;
using namespace std;

int main(){
    const char *fileName="/home/bsxcto/Wedeman_NucPosSimulator/test/params.txt";
    ifstream paramFile;
    paramFile.open(fileName);
    string line;
    string key;
    double value;
    map &lt;string, int&gt; params; #### errors
    while ( paramFile.good() ){
        getline(paramFile, line);
        istringstream ss(line);
        ss &gt;&gt; key &gt;&gt; value; # set the variables  
        params[key] = value; # input them into the map 
    }
inFile.close();
return 0;
}
</code></pre>

<p>However it's on the initialisation of the map structure that I get a bunch of errors:</p>

<pre><code>Multiple markers at this line
    - ‘value’ cannot appear in a constant-
     expression
    - ‘key’ cannot appear in a constant-expression
    - template argument 2 is invalid
    - template argument 1 is invalid
    - template argument 4 is invalid
    - template argument 3 is invalid
    - invalid type in declaration before ‘;’ token
</code></pre>

<p>I have also tried 'map' and 'map', but they do not work either.
Can anyone help with this?</p>
