title: C++: using fstream, maps, and output
body: <p>I am trying to open a text file, and from this, read each line, and map each word occurrence to the line number it is on. Then, I want to print the map.
  Here is my code:</p>
  
  <pre><code>#include &lt;map&gt;
  #include &lt;set&gt;
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;sstream&gt;
  using namespace std;
  int main(){
  
  std::map&lt;string, set&lt;int&gt;&gt; myMap;
  ifstream myFile;
  string myLine ="";
  int lineNum = 0;
  stringstream myStream;
  string myWord ="";
  set&lt;int&gt; mySet;
  
  myFile.open("myTextFile.txt");
  if(myFile.is_open()){
      while (!myFile.eof()){
          getline(myFile, myLine);
          myStream.str(myLine);
          ++lineNum;
          while (!mySStream.eof())
          {
              myStream &gt;&gt; myWord;
              myMap[myWord].insert(lineNum);
  
          }           
          myStream.clear();
     }
  }
  myFile.close();
  // at this point, I expect everything to have been mapped
  // mapping each word occurrence to a line
  //I now want to print the map but out does not work, and I need to use an iterator
  //I have tried this:
  map&lt;string, set&lt;int&gt;&gt;::iterator iter;
  for (iter = myMap.begin(); iter != myMap.end(); ++iter)
  {
      cout &lt;&lt; "Key: " &lt;&lt; iter-&gt;first &lt;&lt; endl &lt;&lt; "Values:" &lt;&lt; endl;
      set&lt;int&gt;::iterator setIter;
      for ( setIter = iter-&gt;second.begin(); setIter != iter-&gt;second.end(); ++setIter)
          cout &lt;&lt; " " &lt;&lt; *setIter&lt;&lt; endl;
  }
  return 0;
  
  }
  </code></pre>
  
  <p>I have no output. Why not?
  Secondly, is everything being properly mapped?</p>