title: C++ putback member function
body: <p>I was studying this book "Problem solving with c++" when I came across this text:
  "Notice that putback places a character in an input stream, while put places
  a character in an output stream. The character that is put back into the input
  stream with the member function putback need not be the last character read;
  it can be any character you wish. If you put back a character other than the
  last character read, the text in the input file will not be changed by putback,
  although your program will behave as if the text in the input file had been
  changed."</p>
  
  <p>I implemented a small program to figure out if this is true or not:</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;fstream&gt;
  
  using namespace std;
  
  int main()
  {
      ifstream input;
      ofstream output;
  
      input.open("infile.dat");
      output.open("outfile.dat");
  
      char next;
      input.get(next);
      while (next!='a')
      {
          output.put(next);
          input.get(next);
      }
      input.putback(next);
      input.get(next);
      output&lt;&lt;"haha"&lt;&lt;next;
      input.close();
      output.close();
      return 0;
  }
  </code></pre>
  
  <p>If the book is correct, than the text in the infile.dat should be changed. But when I check the infile.dat, the data in it doesn't change a bit. What am I missing here?</p>