title: What does ifstream::rdbuf() actually do?
body: <p>I have the following code and it works pretty good (other than the fact that it's pretty slow, but I don't care much about that). It doesn't seem intuitive that this would write the entire contents of the infile to the outfile.</p>
  
  <pre><code>// Returns 1 if failed and 0 if successful
  int WriteFileContentsToNewFile(string inFilename, string outFilename)
  {
      ifstream infile(inFilename.c_str(), ios::binary);
      ofstream outfile(outFilename.c_str(), ios::binary);
  
      if( infile.is_open() &amp;&amp; outfile.is_open() &amp;&amp; infile.good() &amp;&amp; outfile.good() )
      {
          outfile &lt;&lt; infile.rdbuf();
  
          outfile.close();
          infile.close();
      }
      else
          return 1;
  
      return 0;
  }
  </code></pre>
  
  <p>Any insight?</p>