title: How to iterate position of the words in a file using vectors c++
body: <p>I have to read <code>dictionary.txt</code> and <code>test.txt</code>. Then, have to check each word in <code>test.txt</code> if it is equal then this word would be added in <code>KnownWords</code> container and the remaining will be in <code>UnknownWords</code> container. I have done so far everything. But, in function <code>DisplayKnownWordStats()</code> I also have to display the position of the words. I tried the following code but it is not giving me correct value of the positions. </p>
  
  <p>Can someone please help me out to get the correct position of the <code>KnownWords</code> from <code>test.txt</code>. </p>
  
  <pre><code>void WordStats::ReadTxtFile()
  {
      std::ifstream ifile(Filename);
      if (!ifile)
      {
          std::cerr &lt;&lt; "Error Opening file " &lt;&lt; Filename &lt;&lt; std::endl;
          exit(1);
      }
      for (std::string word; ifile &gt;&gt; word; )
      {
          transform(word.begin(), word.end(), word.begin(), ::tolower);
          WordMap &amp; Words = (Dictionary.count(word) ? KnownWords : UnknownWords);
          Words[word].push_back(ifile.tellg());
      }
      std::cout &lt;&lt; KnownWords.size() &lt;&lt; " known words read." &lt;&lt; std::endl;
      std::cout &lt;&lt; UnknownWords.size() &lt;&lt; " unknown words read." &lt;&lt; std::endl;
  }
  
  // Displays stats of words in KnownWords
  void WordStats::DisplayKnownWordStats()
  {
      cout &lt;&lt; "            ";
      cout &lt;&lt; "    Word     Count      Position(s)\n";
      for (Paragraph = KnownWords.begin(); Paragraph != KnownWords.end(); ++Paragraph)
      {
          string word = (*Paragraph).first;
          vector&lt;int&gt; vect = (*Paragraph).second;
          int cnt = vect.size();
          cout &lt;&lt; setw(15) &lt;&lt; word &lt;&lt; setw(10) &lt;&lt; cnt &lt;&lt; "   ";
          for (int i = 0; i&lt;cnt; i++)
              cout &lt;&lt; vect[i] &lt;&lt; ' ';   // something wrong with this code
          cout &lt;&lt; endl;
      }
  }
  </code></pre>