title: Copying contents of one file to another in C++
body: <p>I am using the following program to try to copy the contents of a file, src, to another, dest, in C++. The simplified code is given below:</p>
  
  <pre><code>#include &lt;fstream&gt;
  using namespace std;
  int main()
  {
    fstream src("c:\\tplat\test\\secClassMf19.txt", fstream::binary);
    ofstream dest("c:\\tplat\\test\\mf19b.txt", fstream::trunc|fstream::binary);
    dest &lt;&lt; src.rdbuf();
    return 0;
  }
  </code></pre>
  
  <p>When I built and executed the program using CODEBLOCKS ide with GCC Compiler in windows, a new file named "....mf19.txt" was created, but no data was copied into it, and filesize = 0kb. I am positive I have some data in "...secClassMf19.txt".</p>
  
  <p>I experience the same problem when I compiled the same progeam in windows Visual C++ 2008.</p>
  
  <p>Can anyone please help explain why I am getting this unexpected behaviour, and more importantly, how to solve the problem?</p>