title: Can't read file more than once in c++
body: <p>In my assignment i have a problem with reading a file. See the following code segment.</p>
  
  <pre><code>    std::string data;
      std::ifstream fileRead;
  
      fileRead.open("a.txt");
  
      while (fileRead &gt;&gt; data) 
      {
          long a = fileRead.tellg();
          fileRead.seekg (a+1, ios::beg);
  
          std::string check;
          //some code here
  
          while (fileRead &gt;&gt; check)
          {
              //some code here
          }
          fileRead.seekg (a+1, ios::beg);
      }
  </code></pre>
  
  <p>I have to check how many same words are in the file. My logic is, i read a word and keep it in data. Then  i continue reading after that word using fileRead.seekg (a+1, ios::beg); Then i compare each of the words in the file.</p>
  
  <p>After checking whole file i again put my fileobject to next word using this line fileRead.seekg (a+1, ios::beg); But this line is not working. I mean first while loop just work once. Someone please help me out here.</p>
  
  <p>By the way, i am totally new in file operation. So my logic or concept may not be correct in that case tell me what is the right way to do this? But i need to know why first while loop ends just after reading one word?</p>