title: Splitting files in C++
body: <p>I need to split a file into multiple files without compression. I found this on cpp reference </p>
  
  <pre><code>#include &lt;fstream&gt;
  using namespace std;
  
  int main () {
  
  char * buffer;
  long size;
  
  ifstream infile ("test.txt",ifstream::binary);
  ofstream outfile ("new.txt",ofstream::binary);
  
  // get size of file
  infile.seekg(0,ifstream::end);
  size=infile.tellg();
  infile.seekg(0);
  
  // allocate memory for file content
  buffer = new char [size];
  
  // read content of infile
  infile.read (buffer,size);
  
  // write to outfile
  outfile.write (buffer,size);
  
  // release dynamically-allocated memory
  delete[] buffer;
  
  outfile.close();
  infile.close();
  return 0;
  }
  </code></pre>
  
  <p>and I  thought to do it like this. But the problem is ..I can create only the 1st file because I can read data only from the beginning of the file. Can it be done like this and if no..what is the best way to split these files.</p>