title: Misunderstood the usage of cin.unget() while handling I/O files C++
body: <p>For example, I have a file named <code>Bjarne.txt</code> and in it there's the integers: </p>
  
  <pre><code>16   2   3   4
  </code></pre>
  
  <p>I have made a program to read the integers available inside the file and output them to me in the console window , however , I'm trying to use <code>cin.unget()</code> and by that get understanding of what it does actually , here's the source code:</p>
  
  <pre><code>#include &lt;iostream&gt;     
  #include &lt;fstream&gt;      
  using namespace std;
  
  int main () {
  ifstream ifs("Bjarne.txt");
  int a;
  for(int i = 0;i&lt;4;++i){
     ifs&gt;&gt;a;
     cout&lt;&lt;endl&lt;&lt;a;
     if(i==0){
     ifs.unget();
     }
  }
  </code></pre>
  
  <p>And the output is:</p>
  
  <pre><code>16 6 2 3
  </code></pre>
  
  <p>Why is the output like that? ( it should be <code>16 2 3 4</code> ) , it only occurs when I put ifs.unget() in the program , so my questions are , what is the purpose of cin.unget() while using I/O files and why is the number 6 ( as part of 16 ) getting outputted?</p>
  
  <p>Thanks in advance for any help.</p>