title: Seekg(ios::beg) not returning to beginning of redirected input
body: <p>I am making a huffman encoder and to do so i need to read over the input (which will ALWAYS be a redirected file) to record the frequencies, then create the codebook and then read over the input again so i can encode it.</p>
  
  <p>My problem is that i am currently trying to test out how to make the file read over from cin twice.</p>
  
  <p>I read online that cin.seekg(0) or cin.seekg(ios::beg) or cin.seekg(0, ios::beg) all should work perfectly fine so long as the file is redirected and not piped. But when i do that it seems to not do anything at all to the position of cin.</p>
  
  <p>Here is the code that i am currently using:</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include"huffmanNode.h"
  
  using namespace std;
  
      int main(){
  
      //create array that stores each character and it's frequency
      unsigned int frequencies[255];
      //initialize to zero
      for(int i=0; i&lt;255; i++){
          frequencies[i] = 0;
      }
  
      //get input and increment the frequency of corresponding character
      char c;
      while(!cin.eof()){
          cin.get(c);
          frequencies[c]++;
      }
  
      //create initial leafe nodes for all characters that have appeared at least once
      for(int i=0; i&lt;255; i++){
  
          if(frequencies[i] != 0){
              huffmanNode* tempNode = new huffmanNode(i, frequencies[i]);
          }
      }
  
  
      // test readout of the frequency list
      for(int i=0; i&lt;255; i++){
          cout &lt;&lt; "Character: " &lt;&lt; (char)i &lt;&lt; " Frequency: " &lt;&lt; frequencies[i] &lt;&lt; endl;;
      }
  
      //go back to beginning of input
      cin.seekg(ios::beg);
  
      //read over input again, incrementing frequencies. Should result in double the amount of frequencies
   **THIS IS WHERE IT LOOPS FOREVER**
      while(!cin.eof()){
          cin.get(c);
          frequencies[c]++;
      }
  
      //another test readout of the frequency list
      for(int i=0; i&lt;255; i++){
          cout &lt;&lt; "Character: " &lt;&lt; (char)i &lt;&lt; " Double Frequency: " &lt;&lt; frequencies[i] &lt;&lt; endl;
      }
  
  
      return 0;
  }
  </code></pre>
  
  <p>Debugging shows that it gets stuck in the while loop on line 40, and it seems to constantly be getting a newline character. Why would it not exit this loop? I assume that cin.seekg() is not actually resetting the input.</p>