title: To read from file and store data in map c++
body: <p>I am trying to read file contents and store it in map data structure, where I am trying to skip comment section not be included in my map. I am unable to keep my map as expected, I am kind off clueless how to go ahead. I have mentioned how my map should look like. Please suggest me what changes I have to add in my code. Thanks in Advnc :)</p>
  <p>Input file:</p>
  <pre><code># Filename: MyFile
  # Revision: 107
  
  Items              Types       count     price
  snacks             junkfood
  Mango              fruit        5         50
  strawbery          fruit        10        50
  carrot             veggie
  burger             junkfood
  beetroot           veggie       4         20
  cinnamon           masala
  </code></pre>
  <p>Expected output file:
  Stored in <strong>map&lt;string, string&gt;</strong>
  <em>[key]                 [value]</em></p>
  <pre><code>Items      -&gt;        Types       count     price
  snacks     -&gt;        junkfood
  Mango      -&gt;        fruit        5         50
  strawbery  -&gt;        fruit        10        50
  carrot     -&gt;        veggie
  burger     -&gt;        junkfood
  beetroot   -&gt;        veggie       4         20
  cinnamon   -&gt;        masala
  </code></pre>
  <p>CPP file:</p>
  <pre><code>#include &lt;map&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  #include &lt;sstream&gt;
  #include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  #include &lt;iterator&gt;
  
  using namespace std;
  
  typedef std::pair&lt;std::string, std::string&gt; attribute_pair;
  
  void check(ifstream &amp;inputFile, map&lt;string, string&gt; &amp;diffm)
  {
      diffm.clear();
      std::string line;
      while (getline(inputFile, line))
      {
         std::stringstream ss(line);
         attribute_pair attribute;
  
         while (ss &gt;&gt; attribute.first &gt;&gt; attribute.second)
         {
            if (attribute.first != &quot;#&quot;)
                 diffm[attribute.first] = attribute.second;
         }
      }
  }
  
  int main(int argc, char const *argv[])
  {
      map&lt;string, string&gt; list1;
       
      if (argc &gt;= 2)
      {
          std::ifstream inputFile(argv[1]);
          check(inputFile, list1);
  
          map&lt;string, string&gt;::iterator itr;
          for (itr = list1.begin(); itr != list1.end(); itr++)
          {
             cout &lt;&lt; itr-&gt;first &lt;&lt; &quot;     &quot; &lt;&lt; itr-&gt;second &lt;&lt; &quot;\n&quot;;
          }
      }
      else
      {
          std::cerr &lt;&lt; &quot;Usage &lt;prog name here&gt; &lt;filename1 here&gt; &lt;filename2 here&gt;\n&quot;;
          return -2;
      }
  }
  </code></pre>